@blocklet/pages-kit 0.6.45 → 0.6.47

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.
@@ -60,7 +60,6 @@ exports.BuiltinModules = {
60
60
  '@blocklet/pages-kit/builtin/async/react-markdown': {},
61
61
  '@blocklet/pages-kit/builtin/async/react-syntax-highlighter': {},
62
62
  '@blocklet/pages-kit/builtin/async/image-preview': {},
63
- '@blocklet/pages-kit/builtin/async/ai-runtime': {},
64
63
  '@blocklet/pages-kit/builtin/uploader': {},
65
64
  '@blocklet/pages-kit/builtin/color-picker': {},
66
65
  '@blocklet/pages-kit/builtin/markdown/index': {},
@@ -1028,51 +1028,6 @@ export default () =>
1028
1028
  examples: [],
1029
1029
  },
1030
1030
  },
1031
- // '@blocklet/pages-kit/builtin/async/ai-runtime'
1032
- {
1033
- name: '@blocklet/pages-kit/builtin/async/ai-runtime',
1034
- description: 'A ai-runtime component for pages-kit builtin package',
1035
- docs: {
1036
- components: [
1037
- 'CurrentAgent',
1038
- 'CurrentAgentProvider',
1039
- 'CurrentMessage',
1040
- 'CurrentMessageProvider',
1041
- 'Runtime',
1042
- 'ChatBotButton',
1043
- 'SimplePage',
1044
- 'SimpleChat',
1045
- 'PhotoGallery',
1046
- 'AutoForm',
1047
- 'SimpleOutput',
1048
- 'ChatOutput',
1049
- 'PhotoGalleryItem',
1050
- ],
1051
- import: "import * as AiRuntime from '@blocklet/pages-kit/builtin/async/ai-runtime'",
1052
- export: `
1053
- export * from './contexts/CurrentAgent';
1054
- export { default as CurrentAgentProvider } from './contexts/CurrentAgent';
1055
-
1056
- export * from './contexts/CurrentMessage';
1057
- export { default as CurrentMessageProvider } from './contexts/CurrentMessage';
1058
-
1059
- export * from './state/runtime';
1060
- export * from './state/session';
1061
-
1062
- export { default as Runtime } from './runtime/Runtime';
1063
- export { default as ChatBotButton } from './runtime/ChatBotButton';
1064
-
1065
- export { default as SimplePage } from './runtime-components/SimplePage';
1066
- export { default as SimpleChat } from './runtime-components/SimpleChat';
1067
- export { default as PhotoGallery } from './runtime-components/PhotoGallery';
1068
- export { default as AutoForm } from './runtime-components/AutoForm';
1069
- export { default as SimpleOutput } from './runtime-components/SimpleOutput';
1070
- export { default as ChatOutput } from './runtime-components/ChatOutput';
1071
- export { default as PhotoGalleryItem } from './runtime-components/PhotoGalleryItem';
1072
- `,
1073
- examples: [],
1074
- },
1075
- },
1076
1031
  // '@blocklet/pages-kit/builtin/pages-kit'
1077
1032
  {
1078
1033
  name: '@blocklet/pages-kit/builtin/pages-kit',
@@ -111,7 +111,6 @@ function injectGlobalComponents() {
111
111
  '@blocklet/pages-kit/builtin/async/react-markdown': reactMarkdown,
112
112
  '@blocklet/pages-kit/builtin/async/react-syntax-highlighter': reactSyntaxHighlighter,
113
113
  '@blocklet/pages-kit/builtin/async/image-preview': imagePreview,
114
- '@blocklet/pages-kit/builtin/async/ai-runtime': Promise.resolve().then(() => __importStar(require('../builtin/async/ai-runtime'))),
115
114
  '@blocklet/pages-kit/builtin/event-bus': eventBus,
116
115
  '@blocklet/pages-kit/builtin/zod': zod,
117
116
  };
@@ -238,7 +237,7 @@ function injectGlobalComponents() {
238
237
  : [];
239
238
  // create module code
240
239
  const moduleCode = `// GENERATED FILE. DO NOT EDIT.
241
- const moduleSource = window['${builtin_1.BuiltinModulesGlobalVariableName}'].modules['${modulePath}'];
240
+ const moduleSource = window['${builtin_1.BuiltinModulesGlobalVariableName}'].modules['${modulePath}'];
242
241
  ${namedExports.map((name) => `export const ${name} = moduleSource['${name}'];`).join('\n')}
243
242
  ${defaultExports.map((name) => `export const ${name} = moduleSource.default['${name}'];`).join('\n')}
244
243
  export default ${hasDefaultExport ? 'moduleSource.default' : 'moduleSource'};
@@ -13,7 +13,7 @@ const isAsyncModule = (moduleSpecifier) => {
13
13
  if (!moduleSpecifier) {
14
14
  return false;
15
15
  }
16
- return ['@blocklet/pages-kit/builtin/async/ai-runtime'].includes(moduleSpecifier);
16
+ return false;
17
17
  };
18
18
  exports.isAsyncModule = isAsyncModule;
19
19
  // check if the module is a target module
@@ -28,8 +28,23 @@ const createBuiltinModuleTransformer = (ts) => (context) => (file) => {
28
28
  const { factory } = context;
29
29
  // 统一的模块导入收集器
30
30
  const imports = [];
31
+ // Transform dynamic imports in expressions
32
+ const transformNode = (node) => {
33
+ // Handle import() calls
34
+ if (ts.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword) {
35
+ const arg = node.arguments[0];
36
+ if (arg && ts.isStringLiteral(arg) && ((0, exports.isBuiltinModule)(arg.text) || (0, exports.isRelativeModule)(arg.text))) {
37
+ const requireCall = factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier(builtin_1.BuiltinModulesGlobalVariableName), 'require'), undefined, [factory.createStringLiteral(arg.text)]);
38
+ // For dynamic imports, we don't add await - they should return Promise
39
+ // The calling code (like .then()) will handle the Promise
40
+ return requireCall;
41
+ }
42
+ }
43
+ return ts.visitEachChild(node, transformNode, context);
44
+ };
31
45
  // filter and collect the import statements that need to be processed
32
- const statements = file.statements.filter((s) => {
46
+ const statements = file.statements
47
+ .filter((s) => {
33
48
  if (ts.isImportDeclaration(s) &&
34
49
  ts.isStringLiteral(s.moduleSpecifier) &&
35
50
  ((0, exports.isBuiltinModule)(s.moduleSpecifier.text) || (0, exports.isRelativeModule)(s.moduleSpecifier.text))) {
@@ -57,10 +72,12 @@ const createBuiltinModuleTransformer = (ts) => (context) => (file) => {
57
72
  return false;
58
73
  }
59
74
  return true;
60
- });
75
+ })
76
+ .map((statement) => transformNode(statement)); // Transform dynamic imports in remaining statements
61
77
  statements.unshift(...imports.flatMap((importInfo) => {
62
78
  // call inject-global-components require method
63
79
  const requireCall = factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier(builtin_1.BuiltinModulesGlobalVariableName), 'require'), undefined, [factory.createStringLiteral(importInfo.moduleName)]);
80
+ // Only static imports should be async, dynamic imports return Promise
64
81
  const isAsync = (0, exports.isRelativeModule)(importInfo.moduleName) || (0, exports.isAsyncModule)(importInfo.moduleName);
65
82
  // create await expression if the module is ../ or ./
66
83
  const mod = isAsync ? factory.createAwaitExpression(requireCall) : requireCall;