@blocklet/pages-kit 0.2.358 → 0.2.359

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.
@@ -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
  }
@@ -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;