@blocklet/pages-kit 0.2.351 → 0.2.353

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 (22) hide show
  1. package/lib/cjs/builtin/async/ai-runtime/components/AgentErrorBoundary.js +5 -0
  2. package/lib/cjs/builtin/async/ai-runtime/runtime-components/PhotoGallery/index.js +2 -1
  3. package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/MessageView.js +1 -1
  4. package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimplePage/index.js +1 -1
  5. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/Output.js +3 -5
  6. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/Page.js +2 -1
  7. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/components/CodePreview.js +2 -3
  8. package/lib/cjs/components/CustomComponentRenderer/state.js +1 -1
  9. package/lib/cjs/tsconfig.tsbuildinfo +1 -1
  10. package/lib/esm/builtin/async/ai-runtime/components/AgentErrorBoundary.js +5 -0
  11. package/lib/esm/builtin/async/ai-runtime/runtime-components/PhotoGallery/index.js +2 -1
  12. package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/MessageView.js +1 -1
  13. package/lib/esm/builtin/async/ai-runtime/runtime-components/SimplePage/index.js +1 -1
  14. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/Output.js +3 -5
  15. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/Page.js +2 -1
  16. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/components/CodePreview.js +2 -3
  17. package/lib/esm/components/CustomComponentRenderer/state.js +1 -1
  18. package/lib/esm/tsconfig.tsbuildinfo +1 -1
  19. package/lib/types/builtin/async/ai-runtime/runtime-components/V0/components/CodePreview.d.ts +1 -1
  20. package/lib/types/tsconfig.tsbuildinfo +1 -1
  21. package/package.json +2 -2
  22. package/tsconfig.json +2 -1
@@ -1,4 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { SubscriptionErrorType } from '@blocklet/ai-kit/api';
3
+ import { SubscribeErrorAlert } from '@blocklet/ai-kit/components';
2
4
  import { Alert, Button, Stack, alertClasses } from '@mui/material';
3
5
  import { ErrorBoundary } from 'react-error-boundary';
4
6
  import { useLocaleContext } from '../../../locale';
@@ -12,6 +14,9 @@ export function AgentErrorView({ error }) {
12
14
  if (error.type === 'MissingSecretError') {
13
15
  return _jsx(MissingSecretErrorView, {});
14
16
  }
17
+ if (error.type === SubscriptionErrorType.UNSUBSCRIBED) {
18
+ return _jsx(SubscribeErrorAlert, { error: error });
19
+ }
15
20
  return _jsx(Alert, { severity: "error", children: String(error === null || error === void 0 ? void 0 : error.message) });
16
21
  }
17
22
  function MissingSecretErrorView() {
@@ -16,6 +16,7 @@ import { Suspense, memo, useRef } from 'react';
16
16
  import Balancer from 'react-wrap-balancer';
17
17
  import CustomComponentRenderer from '../../../../../components/CustomComponentRenderer';
18
18
  import { useLocaleContext } from '../../../../locale';
19
+ import { AgentErrorView } from '../../components/AgentErrorBoundary';
19
20
  import SimpleHeader from '../../components/Header/SimpleHeader';
20
21
  import LoadingButton from '../../components/LoadingButton';
21
22
  import { useActiveAgent } from '../../contexts/ActiveAgent';
@@ -55,5 +56,5 @@ const OutputItemView = memo(({ message }) => {
55
56
  const { appearanceOutput } = useAppearances({ agentId: message.agentId });
56
57
  if (!(appearanceOutput === null || appearanceOutput === void 0 ? void 0 : appearanceOutput.componentId))
57
58
  return null;
58
- return (_jsx(CurrentAgentProvider, { agentId: message.agentId, children: _jsx(CurrentMessageProvider, { message: message, children: _jsx(Suspense, { children: _jsx(CustomComponentRenderer, { componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProperties }) }) }) }, message.id));
59
+ return (_jsx(CurrentAgentProvider, { agentId: message.agentId, children: _jsx(CurrentMessageProvider, { message: message, children: _jsx(Suspense, { children: _jsx(CustomComponentRenderer, { componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProperties, fallbackRender: AgentErrorView }, message.id) }) }) }, message.id));
59
60
  });
@@ -31,7 +31,7 @@ const MessageView = memo(({ message }) => {
31
31
  const { hideAgentAvatar, hideUserInputs } = (_b = useComponentPreferences()) !== null && _b !== void 0 ? _b : {};
32
32
  if (!(appearanceOutput === null || appearanceOutput === void 0 ? void 0 : appearanceOutput.componentId))
33
33
  return null;
34
- const agentMessage = (_jsx(MessageBodyContainer, { messageRole: "assistant", children: _jsx(CustomComponentRenderer, { componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProperties, fallbackRender: AgentErrorView }) }));
34
+ const agentMessage = (_jsx(MessageBodyContainer, { messageRole: "assistant", children: _jsx(CustomComponentRenderer, { componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProperties, fallbackRender: AgentErrorView }, message.id) }));
35
35
  return (_jsx(CurrentAgentProvider, { agentId: message.agentId, children: _jsx(CurrentMessageProvider, { message: message, children: _jsxs(Stack, { gap: 2, children: [!hideUserInputs && (_jsx(Box, { children: _jsx(UserInfo, { 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: _jsx(Stack, { sx: { alignItems: 'flex-end' }, children: _jsx(MessageBodyContainer, { messageRole: "user", children: _jsx(UserMessageView, {}) }) }) }) })), _jsx(Box, { children: !hideAgentAvatar ? (_jsx(UserInfo, { 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) })] }) }) }));
36
36
  });
37
37
  export default MessageView;
@@ -43,5 +43,5 @@ const OutputItemView = memo(({ message }) => {
43
43
  const { appearanceOutput } = useAppearances({ agentId: message.agentId });
44
44
  if (!(appearanceOutput === null || appearanceOutput === void 0 ? void 0 : appearanceOutput.componentId))
45
45
  return null;
46
- return (_jsx(CurrentAgentProvider, { agentId: message.agentId, children: _jsx(CurrentMessageProvider, { message: message, children: _jsx(Suspense, { children: _jsx(CustomComponentRenderer, { componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProperties, fallbackRender: AgentErrorView }) }) }) }));
46
+ return (_jsx(CurrentAgentProvider, { agentId: message.agentId, children: _jsx(CurrentMessageProvider, { message: message, children: _jsx(Suspense, { children: _jsx(CustomComponentRenderer, { componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProperties, fallbackRender: AgentErrorView }, message.id) }) }) }));
47
47
  });
@@ -111,7 +111,7 @@ export default function V0Output() {
111
111
  onClick: (e) => __awaiter(this, void 0, void 0, function* () {
112
112
  var _c;
113
113
  const { taskid: taskId } = ((_c = e === null || e === void 0 ? void 0 : e.currentTarget) === null || _c === void 0 ? void 0 : _c.dataset) || {};
114
- const currentCode = getCurrentCodeByTaskId(message, taskId);
114
+ const currentCode = getCurrentCodeByTaskId(message);
115
115
  try {
116
116
  yield transpileAndLoadScript(currentCode).then((m) => {
117
117
  var _a, _b, _c;
@@ -178,10 +178,8 @@ export default function V0Output() {
178
178
  disabled,
179
179
  variant: 'contained',
180
180
  color: 'primary',
181
- onClick: (e) => {
182
- var _a;
183
- const { taskid: taskId } = ((_a = e === null || e === void 0 ? void 0 : e.currentTarget) === null || _a === void 0 ? void 0 : _a.dataset) || {};
184
- setCode(getCurrentCodeByTaskId(message, taskId));
181
+ onClick: () => {
182
+ setCode(getCurrentCodeByTaskId(message));
185
183
  },
186
184
  },
187
185
  group: 'codePreview',
@@ -16,6 +16,7 @@ import { Box, Button, Chip, Container, IconButton, Stack, ThemeProvider, Tooltip
16
16
  import { Suspense, useEffect, useMemo, useRef, useState } from 'react';
17
17
  import CustomComponentRenderer from '../../../../../components/CustomComponentRenderer';
18
18
  import { useLocaleContext } from '../../../../locale';
19
+ import { AgentErrorView } from '../../components/AgentErrorBoundary';
19
20
  import { useActiveAgent } from '../../contexts/ActiveAgent';
20
21
  import CurrentAgentProvider from '../../contexts/CurrentAgent';
21
22
  import CurrentMessageProvider from '../../contexts/CurrentMessage';
@@ -292,5 +293,5 @@ function AgentOutputRender({ message }) {
292
293
  const { appearanceOutput } = useAppearances();
293
294
  if (!(appearanceOutput === null || appearanceOutput === void 0 ? void 0 : appearanceOutput.componentId) || !message)
294
295
  return null;
295
- return (_jsx(CurrentAgentProvider, { agentId: message.agentId, children: _jsx(CurrentMessageProvider, { message: message, children: _jsx(Suspense, { children: _jsx(CustomComponentRenderer, { componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProperties }) }) }) }));
296
+ return (_jsx(CurrentAgentProvider, { agentId: message.agentId, children: _jsx(CurrentMessageProvider, { message: message, children: _jsx(Suspense, { children: _jsx(CustomComponentRenderer, { componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProperties, fallbackRender: AgentErrorView }, message.id) }) }) }));
296
297
  }
@@ -140,8 +140,7 @@ export function CodeRenderByMessage({ zoom, message, minHeight = 200, sx, proper
140
140
  } }), children: _jsx(ContentRender, {}) }, message === null || message === void 0 ? void 0 : message.id));
141
141
  }
142
142
  export const CodeRenderByMessageMemo = memo(CodeRenderByMessage);
143
- export function getCurrentCodeByTaskId(message, taskId) {
143
+ export function getCurrentCodeByTaskId(message) {
144
144
  var _a, _b, _c;
145
- // @ts-ignore
146
- return (_c = (_b = (_a = message === null || message === void 0 ? void 0 : message.outputs) === null || _a === void 0 ? void 0 : _a.objects) === null || _b === void 0 ? void 0 : _b.find((item) => item.taskId === taskId)) === null || _c === void 0 ? void 0 : _c[codeField];
145
+ return (_c = (_b = (_a = message === null || message === void 0 ? void 0 : message.outputs) === null || _a === void 0 ? void 0 : _a.objects) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c[codeField];
147
146
  }
@@ -208,7 +208,7 @@ function useTranspileComponent({ componentId, locale, properties, dev: { default
208
208
  export function transpileAndLoadScript(script) {
209
209
  return __awaiter(this, void 0, void 0, function* () {
210
210
  const [ts, { createBuiltinModuleTransformer }] = yield Promise.all([
211
- import('typescript'),
211
+ import('typescript').then((m) => m.default || m),
212
212
  import('../../utils/typescript/builtin-module-transformer'),
213
213
  ]);
214
214
  const compiled = ts.transpileModule(script, {