@blocklet/pages-kit 0.2.358 → 0.2.360

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 (28) hide show
  1. package/lib/cjs/builtin/async/ai-runtime/api/asset.js +23 -0
  2. package/lib/cjs/builtin/async/ai-runtime/contexts/CurrentAgent.js +2 -2
  3. package/lib/cjs/builtin/async/ai-runtime/hooks/use-appearances.js +16 -9
  4. package/lib/cjs/builtin/async/ai-runtime/hooks/use-header-menu.js +4 -1
  5. package/lib/cjs/builtin/async/ai-runtime/runtime/Runtime/index.js +2 -46
  6. package/lib/cjs/builtin/async/ai-runtime/runtime-components/ChatOutput/MessageItemView.js +5 -4
  7. package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/BackgroundImage.js +4 -1
  8. package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/InputsView.js +3 -1
  9. package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/MessageView.js +4 -1
  10. package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/OpeningMessageView.js +9 -1
  11. package/lib/cjs/builtin/async/ai-runtime/state/session.js +5 -3
  12. package/lib/cjs/tsconfig.tsbuildinfo +1 -1
  13. package/lib/esm/builtin/async/ai-runtime/api/asset.js +20 -0
  14. package/lib/esm/builtin/async/ai-runtime/contexts/CurrentAgent.js +2 -2
  15. package/lib/esm/builtin/async/ai-runtime/hooks/use-appearances.js +16 -9
  16. package/lib/esm/builtin/async/ai-runtime/hooks/use-header-menu.js +4 -1
  17. package/lib/esm/builtin/async/ai-runtime/runtime/Runtime/index.js +3 -47
  18. package/lib/esm/builtin/async/ai-runtime/runtime-components/ChatOutput/MessageItemView.js +5 -4
  19. package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/BackgroundImage.js +4 -1
  20. package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/InputsView.js +3 -1
  21. package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/MessageView.js +4 -1
  22. package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/OpeningMessageView.js +9 -1
  23. package/lib/esm/builtin/async/ai-runtime/state/session.js +5 -3
  24. package/lib/esm/tsconfig.tsbuildinfo +1 -1
  25. package/lib/types/builtin/async/ai-runtime/api/asset.d.ts +13 -0
  26. package/lib/types/builtin/async/ai-runtime/hooks/use-appearances.d.ts +26 -2
  27. package/lib/types/tsconfig.tsbuildinfo +1 -1
  28. package/package.json +3 -3
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAssetUrl = getAssetUrl;
4
+ const ufo_1 = require("ufo");
5
+ const request_1 = require("./request");
6
+ const presets = {
7
+ avatar: { w: 80 },
8
+ };
9
+ function getAssetUrl({ blockletDid, aid, filename, w, preset, }) {
10
+ var _a;
11
+ const url = filename && aid && !(filename === null || filename === void 0 ? void 0 : filename.startsWith('http'))
12
+ ? (0, ufo_1.withQuery)((0, ufo_1.joinURL)((0, request_1.getAIRuntimeApiPrefix)(), '/api/agents', aid, 'assets', filename), {
13
+ blockletDid,
14
+ })
15
+ : filename;
16
+ if (!url)
17
+ return url;
18
+ const width = w !== null && w !== void 0 ? w : (_a = presets[preset]) === null || _a === void 0 ? void 0 : _a.w;
19
+ return (0, ufo_1.withQuery)(url, {
20
+ imageFilter: width ? 'resize' : undefined,
21
+ w: width,
22
+ });
23
+ }
@@ -10,7 +10,7 @@ const runtime_1 = require("../state/runtime");
10
10
  function useCurrentAid({ agentId }) {
11
11
  const { aid } = (0, runtime_1.useRuntimeState)();
12
12
  return (0, react_1.useMemo)(() => ({
13
- aid: (0, aid_1.stringifyIdentity)(Object.assign(Object.assign({}, (0, aid_1.parseIdentity)(aid, { rejectWhenError: true })), { assistantId: agentId })),
13
+ aid: (0, aid_1.stringifyIdentity)(Object.assign(Object.assign({}, (0, aid_1.parseIdentity)(aid, { rejectWhenError: true })), { agentId })),
14
14
  }), [aid, agentId]);
15
15
  }
16
16
  const context = (0, react_1.createContext)(undefined);
@@ -22,7 +22,7 @@ function useCurrentAgent(args = {}) {
22
22
  const { blockletDid, aid: runtimeAid, working } = (0, runtime_1.useRuntimeState)();
23
23
  const aidFromParam = (0, react_1.useMemo)(() => args.aid ||
24
24
  (args.agentId
25
- ? (0, aid_1.stringifyIdentity)(Object.assign(Object.assign({}, (0, aid_1.parseIdentity)(runtimeAid, { rejectWhenError: true })), { assistantId: args.agentId }))
25
+ ? (0, aid_1.stringifyIdentity)(Object.assign(Object.assign({}, (0, aid_1.parseIdentity)(runtimeAid, { rejectWhenError: true })), { agentId: args.agentId }))
26
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;
@@ -16,18 +16,25 @@ function useAppearances(args) {
16
16
  const { agent: runtimeAgent } = (0, runtime_1.useRuntimeState)();
17
17
  const { agent } = (0, CurrentAgent_1.useCurrentAgent)(args);
18
18
  const appearancePage = (0, react_1.useMemo)(() => {
19
- var _a, _b;
19
+ var _a, _b, _c, _d;
20
20
  const appearance = (_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.appearance;
21
- return Object.assign(Object.assign({}, appearance), { componentId: (appearance === null || appearance === void 0 ? void 0 : appearance.componentId) || constants_1.DEFAULT_PAGE_COMPONENT_ID });
21
+ if (appearance === null || appearance === void 0 ? void 0 : appearance.componentId)
22
+ return Object.assign(Object.assign({}, appearance), { componentId: appearance.componentId });
23
+ const runtimeAppearance = (_d = (_c = runtimeAgent.outputVariables) === null || _c === void 0 ? void 0 : _c.find((i) => i.name === types_1.RuntimeOutputVariable.appearancePage)) === null || _d === void 0 ? void 0 : _d.appearance;
24
+ if (runtimeAppearance === null || runtimeAppearance === void 0 ? void 0 : runtimeAppearance.componentId)
25
+ return Object.assign(Object.assign({}, runtimeAppearance), { componentId: runtimeAppearance.componentId });
26
+ return {
27
+ componentId: constants_1.DEFAULT_PAGE_COMPONENT_ID,
28
+ };
22
29
  }, [agent]);
23
30
  const appearanceInput = (0, react_1.useMemo)(() => {
24
31
  var _a, _b, _c, _d;
25
32
  const appearance = (_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.appearance;
26
- if (appearance)
27
- return appearance;
33
+ if (appearance === null || appearance === void 0 ? void 0 : appearance.componentId)
34
+ return Object.assign(Object.assign({}, appearance), { componentId: appearance.componentId });
28
35
  const runtimeAppearance = (_d = (_c = runtimeAgent.outputVariables) === null || _c === void 0 ? void 0 : _c.find((i) => i.name === types_1.RuntimeOutputVariable.appearanceInput)) === null || _d === void 0 ? void 0 : _d.appearance;
29
- if (runtimeAppearance)
30
- return runtimeAppearance;
36
+ if (runtimeAppearance === null || runtimeAppearance === void 0 ? void 0 : runtimeAppearance.componentId)
37
+ return Object.assign(Object.assign({}, runtimeAppearance), { componentId: runtimeAppearance.componentId });
31
38
  return {
32
39
  componentId: constants_1.DEFAULT_INPUT_COMPONENT_ID,
33
40
  };
@@ -36,10 +43,10 @@ function useAppearances(args) {
36
43
  var _a, _b, _c, _d;
37
44
  const appearance = (_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.appearance;
38
45
  if (appearance === null || appearance === void 0 ? void 0 : appearance.componentId)
39
- return appearance;
46
+ return Object.assign(Object.assign({}, appearance), { componentId: appearance.componentId });
40
47
  const runtimeAppearance = (_d = (_c = runtimeAgent.outputVariables) === null || _c === void 0 ? void 0 : _c.find((i) => i.name === types_1.RuntimeOutputVariable.appearanceOutput)) === null || _d === void 0 ? void 0 : _d.appearance;
41
- if (runtimeAppearance)
42
- return runtimeAppearance;
48
+ if (runtimeAppearance === null || runtimeAppearance === void 0 ? void 0 : runtimeAppearance.componentId)
49
+ return Object.assign(Object.assign({}, runtimeAppearance), { componentId: runtimeAppearance.componentId });
43
50
  return {
44
51
  componentId: constants_1.DEFAULT_OUTPUT_COMPONENT_ID,
45
52
  };
@@ -21,18 +21,20 @@ const header_1 = require("../../../page/header");
21
21
  const AgentSettingsDialog_1 = require("../components/AgentSettings/AgentSettingsDialog");
22
22
  const PopperMenuButton_1 = __importDefault(require("../components/PopperMenuButton"));
23
23
  const LoadingMenuItem_1 = __importDefault(require("../components/PopperMenuButton/LoadingMenuItem"));
24
+ const SocialShare_1 = __importDefault(require("../components/SocialShare"));
24
25
  const ComponentPreferences_1 = require("../contexts/ComponentPreferences");
25
26
  const runtime_1 = require("../state/runtime");
26
27
  const session_1 = require("../state/session");
27
28
  const use_agent_admin_1 = require("./use-agent-admin");
28
29
  function useHeaderMenu() {
29
- var _a;
30
+ var _a, _b, _c;
30
31
  const { t, locale } = (0, locale_1.useLocaleContext)();
31
32
  const { hideHeaderMenuButton } = (_a = (0, ComponentPreferences_1.useComponentPreferences)()) !== null && _a !== void 0 ? _a : {};
32
33
  const clearSession = (0, session_1.useSessionState)((s) => s.clearSession);
33
34
  const { agent } = (0, runtime_1.useRuntimeState)();
34
35
  const isAdmin = (0, use_agent_admin_1.useIsAgentAdmin)(agent);
35
36
  const hasSettings = agent.config.secrets.length > 0;
37
+ const shareContent = ((_b = agent.project) === null || _b === void 0 ? void 0 : _b.name) ? `${agent.project.name}\n\n${(_c = agent.project) === null || _c === void 0 ? void 0 : _c.description}` : '';
36
38
  (0, header_1.useHeader)(() => hideHeaderMenuButton
37
39
  ? {}
38
40
  : {
@@ -41,6 +43,7 @@ function useHeaderMenu() {
41
43
  hasSettings && isAdmin && ((0, jsx_runtime_1.jsxs)(material_1.MenuItem, { onClick: () => AgentSettingsDialog_1.settingsDialogState.getState().open(), children: [(0, jsx_runtime_1.jsx)(material_1.ListItemIcon, { children: (0, jsx_runtime_1.jsx)(react_1.Icon, { icon: "tabler:settings" }) }), t('settings')] }, "settings")),
42
44
  (0, jsx_runtime_1.jsxs)(LoadingMenuItem_1.default, { onClick: () => __awaiter(this, void 0, void 0, function* () { return clearSession(); }), children: [(0, jsx_runtime_1.jsx)(material_1.ListItemIcon, { children: (0, jsx_runtime_1.jsx)(react_1.Icon, { icon: "mingcute:broom-line" }) }), t('clearSession')] }, "clearSession"),
43
45
  ], children: (0, jsx_runtime_1.jsx)(react_1.Icon, { icon: "tabler:dots" }) }),
46
+ (0, jsx_runtime_1.jsx)(SocialShare_1.default, { content: shareContent }),
44
47
  ...exists,
45
48
  ],
46
49
  }, [locale, hideHeaderMenuButton]);
@@ -28,67 +28,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.default = Runtime;
30
30
  const jsx_runtime_1 = require("react/jsx-runtime");
31
- const material_1 = require("@mui/material");
32
31
  const react_helmet_1 = require("react-helmet");
33
- const ufo_1 = require("ufo");
34
32
  const CustomComponentRenderer_1 = __importDefault(require("../../../../../components/CustomComponentRenderer"));
35
- const ux_1 = require("../../../../arcblock/ux");
36
- const locale_1 = require("../../../../locale");
37
- const header_1 = require("../../../../page/header");
38
- const utils_1 = require("../../../../utils");
39
33
  const AgentSettingsDialog_1 = __importDefault(require("../../components/AgentSettings/AgentSettingsDialog"));
40
- const RuntimeCommonProvider_1 = __importStar(require("../../components/RuntimeCommonProvider"));
41
- const SocialShare_1 = __importDefault(require("../../components/SocialShare"));
34
+ const RuntimeCommonProvider_1 = __importDefault(require("../../components/RuntimeCommonProvider"));
42
35
  const ThemeProvider_1 = __importDefault(require("../../components/ThemeProvider"));
43
- const constants_1 = require("../../constants");
44
36
  const ActiveAgent_1 = __importDefault(require("../../contexts/ActiveAgent"));
45
37
  const Runtime_1 = __importStar(require("../../contexts/Runtime"));
46
38
  const use_appearances_1 = __importDefault(require("../../hooks/use-appearances"));
47
39
  const use_header_menu_1 = require("../../hooks/use-header-menu");
48
40
  const runtime_1 = require("../../state/runtime");
49
- const logoSize = 44;
50
- function AgentCreatedBy({ did }) {
51
- const { t } = (0, locale_1.useLocaleContext)();
52
- 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 })] }));
53
- }
54
41
  function Runtime({ blockletDid, aid, working, }) {
55
42
  const children = ((0, jsx_runtime_1.jsx)(ThemeProvider_1.default, { children: (0, jsx_runtime_1.jsx)(ActiveAgent_1.default, { children: (0, jsx_runtime_1.jsx)(RuntimeView, {}) }) }));
56
43
  return ((0, jsx_runtime_1.jsx)(RuntimeCommonProvider_1.default, { children: aid ? ((0, jsx_runtime_1.jsx)(Runtime_1.default, { blockletDid: blockletDid, aid: aid, working: working, children: children })) : ((0, jsx_runtime_1.jsx)(Runtime_1.RuntimeProviderFromUrl, { children: children })) }));
57
44
  }
58
45
  function RuntimeView() {
59
- var _a;
60
46
  const { aid, agent } = (0, runtime_1.useRuntimeState)();
61
47
  const { appearancePage } = (0, use_appearances_1.default)({ aid });
62
- const theme = (0, material_1.useTheme)();
63
- const isMobile = (0, material_1.useMediaQuery)(theme.breakpoints.down('sm'));
64
- const { locale } = (0, locale_1.useLocaleContext)();
65
- (0, header_1.useHeader)(() => {
66
- 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');
67
- const shareContent = `${agent.name}
68
-
69
- ${agent === null || agent === void 0 ? void 0 : agent.description}
70
- `;
71
- return {
72
- 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: {
73
- width: logoSize,
74
- height: logoSize,
75
- } })),
76
- brand: !isMobile ? ((0, jsx_runtime_1.jsx)(material_1.Box, { sx: {
77
- height: 18,
78
- fontSize: 18,
79
- }, children: agent.project.name })) : undefined,
80
- description: !isMobile && agent.createdBy ? ((0, jsx_runtime_1.jsx)(RuntimeCommonProvider_1.RuntimeLocaleProvider, { children: (0, jsx_runtime_1.jsx)(material_1.Box, { sx: {
81
- display: 'inline-flex',
82
- alignItems: 'center',
83
- gap: 0.5,
84
- mt: 0.5,
85
- height: 12,
86
- fontSize: 12,
87
- }, children: (0, jsx_runtime_1.jsx)(AgentCreatedBy, { did: agent.project.createdBy }) }) })) : undefined,
88
- addons: (exists) => [(0, jsx_runtime_1.jsx)(SocialShare_1.default, { content: shareContent }), ...exists].filter(Boolean),
89
- };
90
- }, [locale, isMobile, agent]);
91
48
  (0, use_header_menu_1.useHeaderMenu)();
92
- const componentId = (_a = appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.componentId) !== null && _a !== void 0 ? _a : constants_1.DEFAULT_PAGE_COMPONENT_ID;
93
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { 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.componentProperties }), (0, jsx_runtime_1.jsx)(AgentSettingsDialog_1.default, {})] }));
49
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { 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: appearancePage.componentId, properties: appearancePage.componentProperties }), (0, jsx_runtime_1.jsx)(AgentSettingsDialog_1.default, {})] }));
94
50
  }
@@ -46,6 +46,7 @@ const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
46
46
  const react_1 = __importStar(require("react"));
47
47
  const ux_1 = require("../../../../arcblock/ux");
48
48
  const session_1 = require("../../../../session");
49
+ const asset_1 = require("../../api/asset");
49
50
  const MarkdownRenderer_1 = __importDefault(require("../../components/MarkdownRenderer"));
50
51
  const ShareActions_1 = __importDefault(require("../../components/ShareActions"));
51
52
  const use_appearances_1 = require("../../hooks/use-appearances");
@@ -112,13 +113,13 @@ function UserMessage({ message, hideAvatar }) {
112
113
  }
113
114
  function AgentMessage({ message, hideAvatar }) {
114
115
  var _a, _b, _c, _d, _e, _f;
115
- const { aid } = (0, runtime_1.useRuntimeState)();
116
+ const { blockletDid, aid } = (0, runtime_1.useRuntimeState)();
116
117
  const profile = (0, use_appearances_1.useProfile)({ aid });
117
118
  const showMainMessage = !!((_a = message.outputs) === null || _a === void 0 ? void 0 : _a.content);
118
119
  const isMessageLoading = (message.loading || !message.outputs) && !message.error;
119
120
  const theme = (0, material_1.useTheme)();
120
121
  const isMobile = (0, material_1.useMediaQuery)(theme.breakpoints.down('sm'));
121
- 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: (_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: 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: (_b = globalThis.blocklet) === null || _b === void 0 ? void 0 : _b.appId, variant: "circle", shape: "circle", src: (0, asset_1.getAssetUrl)({ blockletDid, aid, filename: profile.avatar, preset: '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: {
122
123
  popper: {
123
124
  disablePortal: true,
124
125
  modifiers: [
@@ -147,10 +148,10 @@ function AgentMessage({ message, hideAvatar }) {
147
148
  function MessageItemWrapper(_a) {
148
149
  var _b;
149
150
  var { hideAvatar, agentMessage } = _a, props = __rest(_a, ["hideAvatar", "agentMessage"]);
150
- const { aid } = (0, runtime_1.useRuntimeState)();
151
+ const { blockletDid, aid } = (0, runtime_1.useRuntimeState)();
151
152
  const profile = (0, use_appearances_1.useProfile)({ aid });
152
153
  const [time] = (0, react_1.useState)(() => new Date().toISOString());
153
- 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] })] })) })));
154
+ 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: (0, asset_1.getAssetUrl)({ blockletDid, aid, filename: profile.avatar, preset: '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] })] })) })));
154
155
  }
155
156
  function MessageUserName({ children }) {
156
157
  return ((0, jsx_runtime_1.jsx)(material_1.Typography, { component: "div", noWrap: true, sx: {
@@ -3,9 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = BackgroundImage;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const material_1 = require("@mui/material");
6
+ const asset_1 = require("../../api/asset");
6
7
  const ComponentPreferences_1 = require("../../contexts/ComponentPreferences");
8
+ const runtime_1 = require("../../state/runtime");
7
9
  function BackgroundImage() {
8
10
  var _a, _b;
11
+ const { blockletDid, aid } = (0, runtime_1.useRuntimeState)();
9
12
  const preferences = (0, ComponentPreferences_1.useComponentPreferences)();
10
13
  if (!((_a = preferences === null || preferences === void 0 ? void 0 : preferences.backgroundImage) === null || _a === void 0 ? void 0 : _a.url))
11
14
  return null;
@@ -15,7 +18,7 @@ function BackgroundImage() {
15
18
  top: 0,
16
19
  right: 0,
17
20
  bottom: 0,
18
- backgroundImage: `url(${(_b = preferences.backgroundImage) === null || _b === void 0 ? void 0 : _b.url}) !important`,
21
+ backgroundImage: `url(${(0, asset_1.getAssetUrl)({ blockletDid, aid, filename: (_b = preferences.backgroundImage) === null || _b === void 0 ? void 0 : _b.url })}) !important`,
19
22
  backgroundRepeat: 'no-repeat',
20
23
  backgroundSize: 'cover',
21
24
  backgroundPosition: 'center',
@@ -43,6 +43,7 @@ const types_1 = require("@blocklet/ai-runtime/types");
43
43
  const material_1 = require("@mui/material");
44
44
  const react_1 = require("react");
45
45
  const CustomComponentRenderer_1 = __importDefault(require("../../../../../components/CustomComponentRenderer"));
46
+ const asset_1 = require("../../api/asset");
46
47
  const ActiveAgent_1 = require("../../contexts/ActiveAgent");
47
48
  const CurrentAgent_1 = __importStar(require("../../contexts/CurrentAgent"));
48
49
  const use_appearances_1 = __importStar(require("../../hooks/use-appearances"));
@@ -58,11 +59,12 @@ function InputsView(_a) {
58
59
  function AgentAvatar(_a) {
59
60
  var _b;
60
61
  var { selected } = _a, props = __rest(_a, ["selected"]);
62
+ const { blockletDid, aid } = (0, runtime_1.useRuntimeState)();
61
63
  const { appearanceInput } = (0, use_appearances_1.default)();
62
64
  const profile = (0, use_appearances_1.useProfile)();
63
65
  if (!(appearanceInput === null || appearanceInput === void 0 ? void 0 : appearanceInput.componentId))
64
66
  return null;
65
- 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) }) })));
67
+ 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: (0, asset_1.getAssetUrl)({ blockletDid, aid, filename: profile === null || profile === void 0 ? void 0 : profile.avatar, preset: 'avatar' }), children: (_b = profile.name) === null || _b === void 0 ? void 0 : _b.slice(0, 1) }) })));
66
68
  }
67
69
  function AgentInput() {
68
70
  const { aid } = (0, CurrentAgent_1.useCurrentAgent)();
@@ -43,15 +43,18 @@ const material_1 = require("@mui/material");
43
43
  const react_1 = require("react");
44
44
  const CustomComponentRenderer_1 = __importDefault(require("../../../../../components/CustomComponentRenderer"));
45
45
  const session_1 = require("../../../../session");
46
+ const asset_1 = require("../../api/asset");
46
47
  const AgentErrorBoundary_1 = require("../../components/AgentErrorBoundary");
47
48
  const UserInfo_1 = __importDefault(require("../../components/UserInfo"));
48
49
  const ComponentPreferences_1 = require("../../contexts/ComponentPreferences");
49
50
  const CurrentAgent_1 = __importDefault(require("../../contexts/CurrentAgent"));
50
51
  const CurrentMessage_1 = __importDefault(require("../../contexts/CurrentMessage"));
51
52
  const use_appearances_1 = __importStar(require("../../hooks/use-appearances"));
53
+ const runtime_1 = require("../../state/runtime");
52
54
  const UserMessageView_1 = __importDefault(require("./UserMessageView"));
53
55
  const MessageView = (0, react_1.memo)(({ message }) => {
54
56
  var _a, _b, _c, _d, _e, _f;
57
+ const { aid, blockletDid } = (0, runtime_1.useRuntimeState)();
55
58
  const preferences = (0, ComponentPreferences_1.useComponentPreferences)();
56
59
  const hasBg = !!((_a = preferences === null || preferences === void 0 ? void 0 : preferences.backgroundImage) === null || _a === void 0 ? void 0 : _a.url);
57
60
  const { session: authSession } = (0, session_1.useSessionContext)();
@@ -61,7 +64,7 @@ const MessageView = (0, react_1.memo)(({ message }) => {
61
64
  if (!(appearanceOutput === null || appearanceOutput === void 0 ? void 0 : appearanceOutput.componentId))
62
65
  return null;
63
66
  const agentMessage = ((0, jsx_runtime_1.jsx)(MessageBodyContainer, { messageRole: "assistant", children: (0, jsx_runtime_1.jsx)(CustomComponentRenderer_1.default, { componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProperties, fallbackRender: AgentErrorBoundary_1.AgentErrorView }, message.id) }));
64
- return ((0, jsx_runtime_1.jsx)(CurrentAgent_1.default, { agentId: message.agentId, children: (0, jsx_runtime_1.jsx)(CurrentMessage_1.default, { message: message, children: (0, jsx_runtime_1.jsxs)(material_1.Stack, { gap: 2, children: [!hideUserInputs && ((0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(UserInfo_1.default, { name: (_c = authSession.user) === null || _c === void 0 ? void 0 : _c.fullName, did: (_d = authSession.user) === null || _d === void 0 ? void 0 : _d.did, avatar: (_e = authSession.user) === null || _e === void 0 ? void 0 : _e.avatar, time: message.createdAt, reverse: true, alignItems: "flex-start", UserNameProps: { sx: { color: hasBg ? 'white' : undefined } }, children: (0, jsx_runtime_1.jsx)(material_1.Stack, { sx: { alignItems: 'flex-end' }, children: (0, jsx_runtime_1.jsx)(MessageBodyContainer, { messageRole: "user", children: (0, jsx_runtime_1.jsx)(UserMessageView_1.default, {}) }) }) }) })), (0, jsx_runtime_1.jsx)(material_1.Box, { children: !hideAgentAvatar ? ((0, jsx_runtime_1.jsx)(UserInfo_1.default, { name: profile.name, did: (_f = globalThis.blocklet) === null || _f === void 0 ? void 0 : _f.appId, avatar: profile.avatar, time: message.createdAt, alignItems: "flex-start", UserNameProps: { sx: { color: hasBg ? 'white' : undefined } }, children: agentMessage })) : (agentMessage) })] }) }) }));
67
+ return ((0, jsx_runtime_1.jsx)(CurrentAgent_1.default, { agentId: message.agentId, children: (0, jsx_runtime_1.jsx)(CurrentMessage_1.default, { message: message, children: (0, jsx_runtime_1.jsxs)(material_1.Stack, { gap: 2, children: [!hideUserInputs && ((0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(UserInfo_1.default, { name: (_c = authSession.user) === null || _c === void 0 ? void 0 : _c.fullName, did: (_d = authSession.user) === null || _d === void 0 ? void 0 : _d.did, avatar: (0, asset_1.getAssetUrl)({ filename: (_e = authSession.user) === null || _e === void 0 ? void 0 : _e.avatar, preset: 'avatar' }), time: message.createdAt, reverse: true, alignItems: "flex-start", UserNameProps: { sx: { color: hasBg ? 'white' : undefined } }, children: (0, jsx_runtime_1.jsx)(material_1.Stack, { sx: { alignItems: 'flex-end' }, children: (0, jsx_runtime_1.jsx)(MessageBodyContainer, { messageRole: "user", children: (0, jsx_runtime_1.jsx)(UserMessageView_1.default, {}) }) }) }) })), (0, jsx_runtime_1.jsx)(material_1.Box, { children: !hideAgentAvatar ? ((0, jsx_runtime_1.jsx)(UserInfo_1.default, { name: profile.name, did: (_f = globalThis.blocklet) === null || _f === void 0 ? void 0 : _f.appId, avatar: (0, asset_1.getAssetUrl)({ blockletDid, aid, filename: profile.avatar, preset: 'avatar' }), time: message.createdAt, alignItems: "flex-start", UserNameProps: { sx: { color: hasBg ? 'white' : undefined } }, children: agentMessage })) : (agentMessage) })] }) }) }));
65
68
  });
66
69
  exports.default = MessageView;
67
70
  function MessageBodyContainer(_a) {
@@ -7,14 +7,17 @@ const jsx_runtime_1 = require("react/jsx-runtime");
7
7
  const types_1 = require("@blocklet/ai-runtime/types");
8
8
  const react_1 = require("react");
9
9
  const CustomComponentRenderer_1 = __importDefault(require("../../../../../components/CustomComponentRenderer"));
10
+ const asset_1 = require("../../api/asset");
10
11
  const UserInfo_1 = __importDefault(require("../../components/UserInfo"));
11
12
  const constants_1 = require("../../constants");
12
13
  const ComponentPreferences_1 = require("../../contexts/ComponentPreferences");
13
14
  const CurrentAgent_1 = require("../../contexts/CurrentAgent");
14
15
  const use_appearances_1 = require("../../hooks/use-appearances");
16
+ const runtime_1 = require("../../state/runtime");
15
17
  const MessageView_1 = require("./MessageView");
16
18
  const OpeningMessageView = (0, react_1.memo)(({ isMessagesEmpty }) => {
17
19
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
20
+ const { blockletDid, aid } = (0, runtime_1.useRuntimeState)();
18
21
  const { hideAgentAvatar, backgroundImage } = (_a = (0, ComponentPreferences_1.useComponentPreferences)()) !== null && _a !== void 0 ? _a : {};
19
22
  const hasBg = !!(backgroundImage === null || backgroundImage === void 0 ? void 0 : backgroundImage.url);
20
23
  const openingMessage = (0, use_appearances_1.useOpeningMessage)();
@@ -32,6 +35,11 @@ const OpeningMessageView = (0, react_1.memo)(({ isMessagesEmpty }) => {
32
35
  return null;
33
36
  }
34
37
  const children = ((0, jsx_runtime_1.jsxs)(MessageView_1.MessageBodyContainer, { children: [openingMessage && openingMessageOutput && openingMessageComponentId && ((0, jsx_runtime_1.jsx)(CustomComponentRenderer_1.default, { instanceId: openingMessageOutput.id, componentId: openingMessageComponentId, properties: (_f = openingMessageOutput.appearance) === null || _f === void 0 ? void 0 : _f.componentProperties, props: { output: openingMessageOutput, outputValue: openingMessage.message } })), isMessagesEmpty && openingQuestionsComponentId && ((0, jsx_runtime_1.jsx)(CustomComponentRenderer_1.default, { instanceId: agent.id, componentId: openingQuestionsComponentId, properties: (_g = openingQuestionsOutput === null || openingQuestionsOutput === void 0 ? void 0 : openingQuestionsOutput.appearance) === null || _g === void 0 ? void 0 : _g.componentProperties, props: { output: openingQuestionsOutput } }))] }));
35
- return hideAgentAvatar ? (children) : ((0, jsx_runtime_1.jsx)(UserInfo_1.default, { name: ((_h = openingMessage === null || openingMessage === void 0 ? void 0 : openingMessage.profile) !== null && _h !== void 0 ? _h : profile).name, did: (_j = globalThis.blocklet) === null || _j === void 0 ? void 0 : _j.appId, avatar: ((_k = openingMessage === null || openingMessage === void 0 ? void 0 : openingMessage.profile) !== null && _k !== void 0 ? _k : profile).avatar, alignItems: "flex-start", UserNameProps: { sx: { color: hasBg ? 'white' : undefined } }, children: children }));
38
+ return hideAgentAvatar ? (children) : ((0, jsx_runtime_1.jsx)(UserInfo_1.default, { name: ((_h = openingMessage === null || openingMessage === void 0 ? void 0 : openingMessage.profile) !== null && _h !== void 0 ? _h : profile).name, did: (_j = globalThis.blocklet) === null || _j === void 0 ? void 0 : _j.appId, avatar: (0, asset_1.getAssetUrl)({
39
+ blockletDid,
40
+ aid,
41
+ filename: ((_k = openingMessage === null || openingMessage === void 0 ? void 0 : openingMessage.profile) !== null && _k !== void 0 ? _k : profile).avatar,
42
+ preset: 'avatar',
43
+ }), alignItems: "flex-start", UserNameProps: { sx: { color: hasBg ? 'white' : undefined } }, children: children }));
36
44
  });
37
45
  exports.default = OpeningMessageView;
@@ -274,6 +274,7 @@ const createSessionState = ({ aid }) => {
274
274
  parameters: Object.assign(Object.assign({}, parameters), { $clientTime: new Date().toISOString() }),
275
275
  });
276
276
  let responseStarted = false;
277
+ let mainTaskId;
277
278
  try {
278
279
  for (var _e = true, stream_1 = __asyncValues(stream), stream_1_1; stream_1_1 = yield stream_1.next(), _b = stream_1_1.done, !_b; _e = true) {
279
280
  _d = stream_1_1.value;
@@ -285,9 +286,10 @@ const createSessionState = ({ aid }) => {
285
286
  }
286
287
  if ((value === null || value === void 0 ? void 0 : value.type) === 'CHUNK') {
287
288
  if (!message) {
289
+ mainTaskId = value.taskId;
288
290
  message = {
289
- id: value.taskId,
290
- agentId: identity.assistantId,
291
+ id: value.messageId,
292
+ agentId: identity.agentId,
291
293
  sessionId,
292
294
  inputs: parameters,
293
295
  createdAt: new Date().toISOString(),
@@ -303,7 +305,7 @@ const createSessionState = ({ aid }) => {
303
305
  s.messages.push(message);
304
306
  });
305
307
  }
306
- if (message.id === value.taskId) {
308
+ if (mainTaskId === value.taskId) {
307
309
  requestAnimationFrame(() => {
308
310
  set((state) => {
309
311
  var _a, _b, _c, _d;