@lark-apaas/miaoda-core 0.1.0-alpha.14 → 0.1.0-alpha.16

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 (45) hide show
  1. package/lib/apis/dataloom.d.ts +1 -1
  2. package/lib/apis/dataloom.js +2 -2
  3. package/lib/apis/utils/registerChinaMap.js +34 -34
  4. package/lib/components/AppContainer/IframeBridge.js +62 -96
  5. package/lib/components/AppContainer/PageHoc.js +1 -1
  6. package/lib/components/AppContainer/childApi.d.ts +5 -0
  7. package/lib/components/AppContainer/childApi.js +20 -0
  8. package/lib/components/ErrorRender/index.js +4 -4
  9. package/lib/components/NotFoundRender/index.js +3 -3
  10. package/lib/components/TopNav/BottomNav.js +1 -1
  11. package/lib/components/TopNav/TitleBar.js +5 -5
  12. package/lib/components/TopNav/TopNav.js +1 -1
  13. package/lib/components/User/UserProfile/UserProfileUI.js +4 -4
  14. package/lib/components/User/UserProfile/utils.js +1 -1
  15. package/lib/components/User/UserSelect.js +3 -2
  16. package/lib/components/User/UserWithAvatar.js +1 -1
  17. package/lib/components/Welcome/index.js +3 -3
  18. package/lib/components/common/LogoInfo.js +1 -1
  19. package/lib/components/common/NavItem.js +1 -1
  20. package/lib/components/common/UserAvatarMenu.js +1 -1
  21. package/lib/components/theme/constants.js +3 -3
  22. package/lib/components/theme/util.js +2 -2
  23. package/lib/hooks/useAppInfo.js +4 -3
  24. package/lib/hooks/useCurrentUserProfile.js +5 -2
  25. package/lib/hooks/useLogout.js +7 -5
  26. package/lib/hooks/useTheme.js +1 -1
  27. package/lib/integrations/dataloom.d.ts +2 -1
  28. package/lib/integrations/dataloom.js +11 -6
  29. package/lib/integrations/generateImage.js +2 -1
  30. package/lib/integrations/generateTextStream.d.ts +0 -5
  31. package/lib/integrations/generateTextStream.js +6 -5
  32. package/lib/integrations/getAppInfo.d.ts +1 -1
  33. package/lib/integrations/getAppInfo.js +12 -2
  34. package/lib/types/common.d.ts +0 -7
  35. package/lib/types/iframe-events.d.ts +9 -1
  36. package/lib/types/index.d.ts +2 -0
  37. package/lib/utils/copyToClipboard.js +2 -2
  38. package/lib/utils/getAppId.d.ts +0 -5
  39. package/lib/utils/getInitialInfo.d.ts +20 -0
  40. package/lib/utils/getInitialInfo.js +32 -0
  41. package/lib/utils/getParentOrigin.js +2 -2
  42. package/lib/utils/getUserProfile.js +2 -1
  43. package/lib/utils/utils.d.ts +2 -0
  44. package/lib/utils/utils.js +4 -1
  45. package/package.json +21 -19
@@ -16,7 +16,7 @@ const formatI18nProfile = (profile)=>({
16
16
  });
17
17
  const getChatAppLink = (openId)=>`https://applink.feishu.cn/client/chat/open?openId=${openId}`;
18
18
  const INVALID_USER = {
19
- name: '无效人员',
19
+ name: "\u65E0\u6548\u4EBA\u5458",
20
20
  avatar: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/LMfspH/ljhwZthlaukjlkulzlp/miao/no-person.svg',
21
21
  email: '',
22
22
  department: '',
@@ -3,7 +3,7 @@ import { useMemo, useRef, useState } from "react";
3
3
  import { Avatar, Select, Spin } from "antd";
4
4
  import { LoaderCircle } from "lucide-react";
5
5
  import { debounce } from "lodash";
6
- import { dataloom } from "../../integrations/dataloom.js";
6
+ import { getDataloom } from "../../integrations/dataloom.js";
7
7
  import "./UserSelect.css";
8
8
  import { UserWithAvatar } from "./UserWithAvatar.js";
9
9
  const mapValueToOptions = (value)=>{
@@ -57,6 +57,7 @@ const UserSelect = ({ mode = 'single', defaultValue, value, onChange, placeholde
57
57
  const fetchRef = useRef(0);
58
58
  const fetchUsers = async (search)=>{
59
59
  try {
60
+ const dataloom = await getDataloom();
60
61
  const { data } = await dataloom.service.user.search({
61
62
  name: search,
62
63
  pageSize: 20
@@ -140,7 +141,7 @@ const UserSelect = ({ mode = 'single', defaultValue, value, onChange, placeholde
140
141
  })
141
142
  }) : /*#__PURE__*/ jsx("span", {
142
143
  className: "py-[1px] px-1 text-[#8F959E]",
143
- children: "无结果,建议更换搜索词"
144
+ children: "\u65E0\u7ED3\u679C\uFF0C\u5EFA\u8BAE\u66F4\u6362\u641C\u7D22\u8BCD"
144
145
  }),
145
146
  optionRender: optionRender,
146
147
  options: options,
@@ -14,7 +14,7 @@ const textVariantMap = {
14
14
  };
15
15
  function UserWithAvatar({ data, size = 'medium', mode = 'tag', className }) {
16
16
  const { avatar, name } = data;
17
- const displayName = name || '无效人员';
17
+ const displayName = name || "\u65E0\u6548\u4EBA\u5458";
18
18
  return /*#__PURE__*/ jsxs("div", {
19
19
  className: clsxWithTw('flex items-center gap-1 rounded-full', {
20
20
  'bg-[rgba(31,35,41,0.1)]': 'tag' === mode,
@@ -8,15 +8,15 @@ const Welcome = ()=>/*#__PURE__*/ jsxs("div", {
8
8
  children: [
9
9
  /*#__PURE__*/ jsx("div", {
10
10
  className: "text-2xl font-bold mb-3",
11
- children: "欢迎使用妙搭 \uD83D\uDC4B"
11
+ children: "\u6B22\u8FCE\u4F7F\u7528\u5999\u642D \uD83D\uDC4B"
12
12
  }),
13
13
  /*#__PURE__*/ jsx("div", {
14
14
  className: "text-[#646A73] text-sm",
15
- children: "1. 随时发送消息,开始构建你的专属应用"
15
+ children: "1. \u968F\u65F6\u53D1\u9001\u6D88\u606F\uFF0C\u5F00\u59CB\u6784\u5EFA\u4F60\u7684\u4E13\u5C5E\u5E94\u7528"
16
16
  }),
17
17
  /*#__PURE__*/ jsx("div", {
18
18
  className: "text-[#646A73] text-sm",
19
- children: "2. 无需担心代码实现,妙搭帮你一一解决"
19
+ children: "2. \u65E0\u9700\u62C5\u5FC3\u4EE3\u7801\u5B9E\u73B0\uFF0C\u5999\u642D\u5E2E\u4F60\u4E00\u4E00\u89E3\u51B3"
20
20
  })
21
21
  ]
22
22
  }),
@@ -19,7 +19,7 @@ function LogoInfo({ className, logoClassName }) {
19
19
  /*#__PURE__*/ jsxs("span", {
20
20
  className: "w-full truncate",
21
21
  children: [
22
- name || '新应用',
22
+ name || "\u65B0\u5E94\u7528",
23
23
  " "
24
24
  ]
25
25
  })
@@ -80,7 +80,7 @@ const NavItem = /*#__PURE__*/ react.forwardRef((props, ref)=>{
80
80
  });
81
81
  });
82
82
  NavItem.displayName = 'NavItem';
83
- const MoreNavItem = ({ expandedNavItemsPath, onClick, isExpanded, name = '更多', ...restProps })=>{
83
+ const MoreNavItem = ({ expandedNavItemsPath, onClick, isExpanded, name = "\u66F4\u591A", ...restProps })=>{
84
84
  const { pathname } = useLocation();
85
85
  const isActive = useMemo(()=>{
86
86
  const matched = expandedNavItemsPath.some((path)=>{
@@ -36,7 +36,7 @@ function UserAvatarMenu({ className }) {
36
36
  children: [
37
37
  /*#__PURE__*/ jsx(LogOut, {}),
38
38
  /*#__PURE__*/ jsx("span", {
39
- children: "退出登录"
39
+ children: "\u9000\u51FA\u767B\u5F55"
40
40
  })
41
41
  ]
42
42
  })
@@ -1,6 +1,6 @@
1
1
  const themeMetaOptions = {
2
2
  themeColors: {
3
- title: '主题色',
3
+ title: "\u4E3B\u9898\u8272",
4
4
  options: [
5
5
  {
6
6
  value: '--blue-700',
@@ -33,7 +33,7 @@ const themeMetaOptions = {
33
33
  ]
34
34
  },
35
35
  themeRadius: {
36
- title: '圆角',
36
+ title: "\u5706\u89D2",
37
37
  options: [
38
38
  {
39
39
  value: {
@@ -70,7 +70,7 @@ const themeMetaOptions = {
70
70
  ]
71
71
  },
72
72
  themeSpaces: {
73
- title: '间距',
73
+ title: "\u95F4\u8DDD",
74
74
  options: [
75
75
  {
76
76
  value: {
@@ -70,7 +70,7 @@ const generateTailwindRadiusToken = (radiusRemValue)=>{
70
70
  options: [
71
71
  {
72
72
  value: 'rounded-none',
73
- label: 'none(0px)',
73
+ label: "none\uFF080px\uFF09",
74
74
  rawValue: '0'
75
75
  },
76
76
  {
@@ -119,7 +119,7 @@ const generateTailwindRadiusToken = (radiusRemValue)=>{
119
119
  options: [
120
120
  {
121
121
  value: 'rounded-none',
122
- label: 'none(0px)',
122
+ label: "none\uFF080px\uFF09",
123
123
  rawValue: '0'
124
124
  },
125
125
  {
@@ -1,11 +1,12 @@
1
1
  import { useEffect, useState } from "react";
2
2
  import { getAppInfo } from "../integrations/getAppInfo.js";
3
3
  const useAppInfo = ()=>{
4
- const [appInfo, setAppInfo] = useState(()=>getAppInfo());
4
+ const [appInfo, setAppInfo] = useState({});
5
5
  useEffect(()=>{
6
- const handleMetaInfoChanged = ()=>{
7
- setAppInfo(getAppInfo());
6
+ const handleMetaInfoChanged = async ()=>{
7
+ setAppInfo(await getAppInfo());
8
8
  };
9
+ handleMetaInfoChanged();
9
10
  window.addEventListener('MiaoDaMetaInfoChanged', handleMetaInfoChanged);
10
11
  return ()=>{
11
12
  window.removeEventListener('MiaoDaMetaInfoChanged', handleMetaInfoChanged);
@@ -1,7 +1,8 @@
1
1
  import { useEffect, useState } from "react";
2
2
  import { logger } from "../logger/index.js";
3
3
  import { getCurrentUserProfile } from "../integrations/getCurrentUserProfile.js";
4
- import { dataloom } from "../integrations/dataloom.js";
4
+ import { getDataloom } from "../integrations/dataloom.js";
5
+ import { isSanboxMode } from "../utils/utils.js";
5
6
  function getCompatibilityUserProfile() {
6
7
  const userInfo = getCurrentUserProfile();
7
8
  return {
@@ -14,8 +15,9 @@ const useCurrentUserProfile = ()=>{
14
15
  const [userInfo, setUserInfo] = useState(()=>getCompatibilityUserProfile());
15
16
  useEffect(()=>{
16
17
  let handleMetaInfoChanged;
17
- if (window._IS_Spark_RUNTIME) {
18
+ if (isSanboxMode()) {
18
19
  (async ()=>{
20
+ const dataloom = await getDataloom();
19
21
  const result = await dataloom.service.session.getUserInfo();
20
22
  const userInfo = result?.data?.user_info;
21
23
  setUserInfo({
@@ -28,6 +30,7 @@ const useCurrentUserProfile = ()=>{
28
30
  });
29
31
  })();
30
32
  handleMetaInfoChanged = async ()=>{
33
+ const dataloom = await getDataloom();
31
34
  const result = await dataloom.service.session.getUserInfo();
32
35
  const userInfo = result?.data?.user_info;
33
36
  const newUserInfo = {
@@ -1,15 +1,17 @@
1
1
  import { useState } from "react";
2
- import { dataloom } from "../integrations/dataloom.js";
2
+ import { getDataloom } from "../integrations/dataloom.js";
3
+ import { isSanboxMode } from "../utils/utils.js";
3
4
  function useLogout() {
4
5
  const [isLoading, setIsLoading] = useState(false);
5
6
  async function handlerLogout() {
6
- if ('production' !== process.env.NODE_ENV) return void console.log('只有生产环境才执行登出');
7
- if (window._IS_Spark_RUNTIME) {
7
+ if ('production' !== process.env.NODE_ENV) return void console.log("\u53EA\u6709\u751F\u4EA7\u73AF\u5883\u624D\u6267\u884C\u767B\u51FA");
8
+ if (isSanboxMode()) {
8
9
  setIsLoading(true);
9
10
  try {
11
+ const dataloom = await getDataloom();
10
12
  await dataloom.service.session.signOut();
11
13
  } catch (error) {
12
- console.error('登出失败', error);
14
+ console.error("\u767B\u51FA\u5931\u8D25", error);
13
15
  } finally{
14
16
  setIsLoading(false);
15
17
  }
@@ -22,7 +24,7 @@ function useLogout() {
22
24
  });
23
25
  window.location.reload();
24
26
  } catch (error) {
25
- console.error('登出失败', error);
27
+ console.error("\u767B\u51FA\u5931\u8D25", error);
26
28
  } finally{
27
29
  setIsLoading(false);
28
30
  }
@@ -2,7 +2,7 @@ import { useContext } from "react";
2
2
  import { ThemeProviderContext } from "../components/theme/index.js";
3
3
  const useTheme = ()=>{
4
4
  const context = useContext(ThemeProviderContext);
5
- if (void 0 === context) throw new Error('useTheme 必须在 ThemeProvider 内使用');
5
+ if (void 0 === context) throw new Error("useTheme \u5FC5\u987B\u5728 ThemeProvider \u5185\u4F7F\u7528");
6
6
  return context;
7
7
  };
8
8
  export { useTheme };
@@ -1 +1,2 @@
1
- export declare const dataloom: import("@data-loom/js").DataloomClient<any, "public", any>;
1
+ /** 获取dataloom实例 */
2
+ export declare function getDataloom(): Promise<import("@data-loom/js").DataloomClient<any, "public", any>>;
@@ -1,10 +1,7 @@
1
1
  import { splitWorkspaceUrl } from "../utils/url.js";
2
2
  import { createClient } from "@data-loom/js";
3
3
  import { getAppId } from "../utils/getAppId.js";
4
- const PAT_URL_NAMESPACE = 'FEISUDA_UUU';
5
- const PAT_TOKEN_NAMESPACE = 'FEISUDA_TTT';
6
- const DATALOOM_CLIENT_URL = window[PAT_URL_NAMESPACE];
7
- const DATALOOM_PAT = window[PAT_TOKEN_NAMESPACE];
4
+ import { getInitialInfo } from "../utils/getInitialInfo.js";
8
5
  const createDataLoomClient = (url, pat)=>{
9
6
  if (!url) return null;
10
7
  const { baseUrl, workspace } = splitWorkspaceUrl(url);
@@ -23,5 +20,13 @@ const createDataLoomClient = (url, pat)=>{
23
20
  }
24
21
  });
25
22
  };
26
- const dataloom = createDataLoomClient(DATALOOM_CLIENT_URL, DATALOOM_PAT);
27
- export { dataloom };
23
+ let dataloom = null;
24
+ async function getDataloom() {
25
+ if (dataloom) return dataloom;
26
+ const { app_runtime_extra } = await getInitialInfo();
27
+ const DATALOOM_CLIENT_URL = app_runtime_extra?.url;
28
+ const DATALOOM_PAT = app_runtime_extra?.token;
29
+ dataloom = createDataLoomClient(DATALOOM_CLIENT_URL, DATALOOM_PAT);
30
+ return dataloom;
31
+ }
32
+ export { getDataloom };
@@ -1,6 +1,7 @@
1
1
  import { getAppId } from "../utils/getAppId.js";
2
2
  import { getCsrfToken } from "../utils/getCsrfToken.js";
3
3
  import { getEnvPath } from "../utils/getEnvPath.js";
4
+ import { isSanboxMode } from "../utils/utils.js";
4
5
  async function generateImage(prompt, size = '1024x1024', headers = {}) {
5
6
  const appId = getAppId(window.location.pathname);
6
7
  if (!appId) return {
@@ -19,7 +20,7 @@ async function generateImage(prompt, size = '1024x1024', headers = {}) {
19
20
  'x-lgw-csrf-token': window.lgw_csrf_token,
20
21
  ...window.CSRF_HEADERS || {}
21
22
  };
22
- if (window._IS_Spark_RUNTIME) {
23
+ if (isSanboxMode()) {
23
24
  mergedHeaders['X-Suda-Csrf-Token'] = getCsrfToken();
24
25
  const response = await fetch(`${window.location.origin}/spark/b/${appId}/text2image`, {
25
26
  method: 'POST',
@@ -1,8 +1,3 @@
1
- declare global {
2
- interface Window {
3
- token?: string;
4
- }
5
- }
6
1
  interface GenerateTextOptions {
7
2
  text: string;
8
3
  thinking_type?: 'enabled' | 'disabled';
@@ -1,6 +1,7 @@
1
1
  import { getAppId } from "../utils/getAppId.js";
2
2
  import { getCsrfToken } from "../utils/getCsrfToken.js";
3
3
  import { getEnvPath } from "../utils/getEnvPath.js";
4
+ import { isSanboxMode } from "../utils/utils.js";
4
5
  async function generateTextStream(options, onChunk) {
5
6
  const { text, thinking_type = 'disabled', headers = {} } = options;
6
7
  const appId = getAppId(window.location.pathname);
@@ -20,7 +21,7 @@ async function generateTextStream(options, onChunk) {
20
21
  ...window.CSRF_HEADERS || {}
21
22
  };
22
23
  let response;
23
- if (window._IS_Spark_RUNTIME) {
24
+ if (isSanboxMode()) {
24
25
  mergedHeaders['X-Suda-Csrf-Token'] = getCsrfToken();
25
26
  response = await fetch(`${window.location.origin}/spark/b/${appId}/text/generate`, {
26
27
  method: 'POST',
@@ -42,7 +43,7 @@ async function generateTextStream(options, onChunk) {
42
43
  });
43
44
  if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
44
45
  const reader = response.body?.getReader();
45
- if (!reader) throw new Error('无法获取响应流');
46
+ if (!reader) throw new Error("\u65E0\u6CD5\u83B7\u53D6\u54CD\u5E94\u6D41");
46
47
  let fullContent = '';
47
48
  let fullReasoningContent = '';
48
49
  const decoder = new TextDecoder();
@@ -61,7 +62,7 @@ async function generateTextStream(options, onChunk) {
61
62
  content: '',
62
63
  reasoning_content: '',
63
64
  success: false,
64
- error: data.msg || '生成失败'
65
+ error: data.msg || "\u751F\u6210\u5931\u8D25"
65
66
  };
66
67
  if (data.data.content) fullContent += data.data.content;
67
68
  if (data.data.reasoning_content) fullReasoningContent += data.data.reasoning_content;
@@ -76,7 +77,7 @@ async function generateTextStream(options, onChunk) {
76
77
  success: true
77
78
  };
78
79
  } catch (parseError) {
79
- console.error(`解析JSON失败: ${jsonStr}`);
80
+ console.error(`\u{89E3}\u{6790}JSON\u{5931}\u{8D25}: ${jsonStr}`);
80
81
  }
81
82
  }
82
83
  }
@@ -90,7 +91,7 @@ async function generateTextStream(options, onChunk) {
90
91
  content: '',
91
92
  reasoning_content: '',
92
93
  success: false,
93
- error: error instanceof Error ? error.message : '未知错误'
94
+ error: error instanceof Error ? error.message : "\u672A\u77E5\u9519\u8BEF"
94
95
  };
95
96
  }
96
97
  }
@@ -1,2 +1,2 @@
1
1
  import { AppInfoPayload } from '../types/common';
2
- export declare function getAppInfo(): AppInfoPayload;
2
+ export declare function getAppInfo(): Promise<AppInfoPayload>;
@@ -1,4 +1,14 @@
1
- function getAppInfo() {
2
- return window._appInfo || {};
1
+ import { getInitialInfo } from "../utils/getInitialInfo.js";
2
+ import { isSanboxMode } from "../utils/utils.js";
3
+ async function getAppInfo() {
4
+ let appInfo = window._appInfo;
5
+ if (!appInfo && isSanboxMode()) {
6
+ const info = (await getInitialInfo()).app_info;
7
+ appInfo = {
8
+ name: info?.app_name || '',
9
+ avatar: info?.app_avatar || ''
10
+ };
11
+ }
12
+ return appInfo ?? {};
3
13
  }
4
14
  export { getAppInfo };
@@ -2,10 +2,3 @@ export interface AppInfoPayload {
2
2
  name: string;
3
3
  avatar: string;
4
4
  }
5
- declare global {
6
- interface Window {
7
- MIAODA_APP_ID?: string;
8
- MIAODA_BUILTIN_TTT?: string;
9
- token?: string;
10
- }
11
- }
@@ -30,8 +30,16 @@ export interface UpdateRoutesMessage extends IframeMessage<{
30
30
  }> {
31
31
  type: 'UpdateRoutes';
32
32
  }
33
- export type OutgoingMessage = PreviewReadyMessage | ConsoleMessage | ChildLocationChangeMessage | CreatePageMessage | RenderErrorMessage | RenderErrorRepairMessage | PageScreenshotMessage | UpdateRoutesMessage;
33
+ export interface HmrMessage extends IframeMessage<Record<string, never>> {
34
+ type: 'Hmr';
35
+ }
36
+ export type OutgoingMessage = PreviewReadyMessage | HmrMessage | ConsoleMessage | ChildLocationChangeMessage | CreatePageMessage | RenderErrorMessage | RenderErrorRepairMessage | PageScreenshotMessage | UpdateRoutesMessage;
34
37
  export interface GetRoutesMessage extends IframeMessage<Record<string, never>> {
35
38
  type: 'GetRoutes';
36
39
  }
37
40
  export type IncomingMessage = GetRoutesMessage;
41
+ export interface ParentApi {
42
+ }
43
+ export interface ChildApi {
44
+ getRoutes: () => Promise<any[]>;
45
+ }
@@ -36,5 +36,7 @@ declare global {
36
36
  MIAODA_BUILTIN_TTT?: string;
37
37
  MIAODA_APP_ID?: string;
38
38
  IS_MIAODA_PREVIEW?: boolean;
39
+ _IS_Spark_RUNTIME?: boolean;
40
+ _bucket_id?: string;
39
41
  }
40
42
  }
@@ -6,7 +6,7 @@ async function copyToClipboard(text) {
6
6
  }
7
7
  return fallbackCopyToClipboard(text);
8
8
  } catch (error) {
9
- console.error('复制到剪切板失败:', error);
9
+ console.error("\u590D\u5236\u5230\u526A\u5207\u677F\u5931\u8D25:", error);
10
10
  return false;
11
11
  }
12
12
  }
@@ -25,7 +25,7 @@ function fallbackCopyToClipboard(text) {
25
25
  document.body.removeChild(textArea);
26
26
  return successful;
27
27
  } catch (error) {
28
- console.error('降级复制方案失败:', error);
28
+ console.error("\u964D\u7EA7\u590D\u5236\u65B9\u6848\u5931\u8D25:", error);
29
29
  return false;
30
30
  }
31
31
  }
@@ -1,8 +1,3 @@
1
- declare global {
2
- interface Window {
3
- MIAODA_APP_ID?: string;
4
- }
5
- }
6
1
  /**
7
2
  * 提取固定前缀后的第一个目录名
8
3
  * @param {string} path - 输入路径字符串
@@ -0,0 +1,20 @@
1
+ interface AppRuntimeExtra {
2
+ token?: string;
3
+ url?: string;
4
+ bucket?: BucketConfig;
5
+ }
6
+ interface AppRuntimePublished {
7
+ app_name?: string;
8
+ css_urls?: string[];
9
+ js_urls?: string[];
10
+ app_avatar?: string;
11
+ }
12
+ interface BucketConfig {
13
+ default_bucket_id?: string;
14
+ }
15
+ /** 获取应用初始化信息(仅全栈沙箱模式下使用) */
16
+ export declare function getInitialInfo(): Promise<{
17
+ app_info?: AppRuntimePublished;
18
+ app_runtime_extra?: AppRuntimeExtra;
19
+ }>;
20
+ export {};
@@ -0,0 +1,32 @@
1
+ import { getAppId } from "./getAppId.js";
2
+ import { getCsrfToken } from "./getCsrfToken.js";
3
+ async function getAppPublished() {
4
+ try {
5
+ const headers = {
6
+ 'Content-Type': 'application/json',
7
+ 'X-Kunlun-Token': window.token,
8
+ 'x-miaoda-token': window.MIAODA_BUILTIN_TTT,
9
+ 'X-Suda-Csrf-Token': getCsrfToken()
10
+ };
11
+ const appId = getAppId(window.location.pathname) || window.appId;
12
+ const url = `${window.location.origin}/spark/b/${appId}/get_published`;
13
+ const response = await fetch(url, {
14
+ method: 'GET',
15
+ headers,
16
+ credentials: 'include'
17
+ });
18
+ const res = await response.json();
19
+ if (0 === res.code) return res.data;
20
+ console.error('Error fetching published app info:', res);
21
+ } catch (error) {
22
+ console.error('Error fetching published app info:', error);
23
+ }
24
+ }
25
+ let initialInfo;
26
+ async function getInitialInfo() {
27
+ if (initialInfo) return initialInfo;
28
+ initialInfo = await getAppPublished();
29
+ if (initialInfo) window._bucket_id = initialInfo.app_runtime_extra?.bucket?.default_bucket_id;
30
+ return initialInfo;
31
+ }
32
+ export { getInitialInfo };
@@ -1,7 +1,7 @@
1
1
  function getPreviewParentOrigin() {
2
2
  const { origin } = window.location;
3
- if (origin.includes('feishuapp.cn')) return 'https://miaoda.feishu.cn';
4
- if (origin.includes('fsapp.kundou.cn')) return 'https://miaoda.feishu-pre.cn';
3
+ if (origin.includes('miaoda.feishuapp.net')) return 'https://miaoda.feishu.cn';
4
+ if (origin.includes('miaoda-pre.feishuapp.net')) return 'https://miaoda.feishu-pre.cn';
5
5
  return 'https://miaoda.feishu-boe.cn';
6
6
  }
7
7
  export { getPreviewParentOrigin };
@@ -1,6 +1,7 @@
1
1
  import { getAppId } from "./getAppId.js";
2
2
  import { getCsrfToken } from "./getCsrfToken.js";
3
3
  import { getEnvPath } from "./getEnvPath.js";
4
+ import { isSanboxMode } from "./utils.js";
4
5
  async function getUserProfile(request, headers = {}) {
5
6
  const appId = getAppId(window.location.pathname);
6
7
  if (!appId) return {
@@ -21,7 +22,7 @@ async function getUserProfile(request, headers = {}) {
21
22
  };
22
23
  const envPath = getEnvPath();
23
24
  let endpoint;
24
- if (window._IS_Spark_RUNTIME) {
25
+ if (isSanboxMode()) {
25
26
  endpoint = `/spark/b/${appId}/user/profile`;
26
27
  mergedHeaders['X-Suda-Csrf-Token'] = getCsrfToken();
27
28
  } else endpoint = `/ai/api/${envPath}/v1/apps/${appId}/user/profile`;
@@ -15,3 +15,5 @@ export declare function isPreview(): boolean;
15
15
  * 移除末尾的斜杠,确保路径不以斜杠结尾
16
16
  */
17
17
  export declare function normalizeBasePath(basePath?: string): string;
18
+ /** 判断是否是沙箱模式 */
19
+ export declare function isSanboxMode(): any;
@@ -10,4 +10,7 @@ function normalizeBasePath(basePath) {
10
10
  if (!basePath || '/' === basePath) return '';
11
11
  return basePath.replace(/\/+$/, '');
12
12
  }
13
- export { clsxWithTw, isPreview, normalizeBasePath };
13
+ function isSanboxMode() {
14
+ return window._IS_Spark_RUNTIME || window.isSanboxMode;
15
+ }
16
+ export { clsxWithTw, isPreview, isSanboxMode, normalizeBasePath };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/miaoda-core",
3
- "version": "0.1.0-alpha.14",
3
+ "version": "0.1.0-alpha.16",
4
4
  "types": "./lib/index.d.ts",
5
5
  "main": "./lib/index.js",
6
6
  "files": [
@@ -57,20 +57,36 @@
57
57
  "types": "./lib/apis/utils/*.d.ts"
58
58
  }
59
59
  },
60
+ "scripts": {
61
+ "tsc": "tsc --declaration",
62
+ "build": "rslib build",
63
+ "build:storybook": "storybook build",
64
+ "bump": "changeset version",
65
+ "change": "changeset",
66
+ "check": "biome check --write",
67
+ "dev": "rslib build --watch",
68
+ "format": "biome format --write",
69
+ "storybook": "storybook dev",
70
+ "test": "echo 0",
71
+ "lint": "eslint src --ext .js,.jsx,.ts,.tsx",
72
+ "lint:fix": "eslint src --ext .js,.jsx,.ts,.tsx --fix",
73
+ "prepublishOnly": "npm run build && node scripts/replace-workspace-alias.js"
74
+ },
60
75
  "dependencies": {
61
76
  "@ant-design/colors": "^7.2.1",
62
77
  "@ant-design/cssinjs": "^1.24.0",
63
78
  "@data-loom/js": "0.3.1",
79
+ "@lark-apaas/miaoda-inspector": "0.1.0-alpha.7",
64
80
  "clsx": "~2.0.1",
65
81
  "dayjs": "^1.11.13",
66
82
  "echarts": "^6.0.0",
67
83
  "html2canvas-pro": "^1.5.11",
68
84
  "lodash": "^4.17.21",
85
+ "penpal": "^6.2.2",
69
86
  "sonner": "~2.0.0",
70
87
  "tailwind-merge": "~2.0.0",
71
88
  "tailwind-variants": "0.3.1",
72
- "tailwindcss-animate": "^1.0.7",
73
- "@lark-apaas/miaoda-inspector": "0.1.0-alpha.6"
89
+ "tailwindcss-animate": "^1.0.7"
74
90
  },
75
91
  "devDependencies": {
76
92
  "@biomejs/biome": "2.0.6",
@@ -91,7 +107,6 @@
91
107
  "@types/node": "^22.10.2",
92
108
  "@types/react": "^18.3.23",
93
109
  "@types/react-dom": "^18.3.7",
94
- "typescript-eslint": "^8.41.0",
95
110
  "antd": "^5.26.6",
96
111
  "eslint": "^8.57.0",
97
112
  "jsdom": "^26.1.0",
@@ -105,6 +120,7 @@
105
120
  "tailwindcss": "^4.1.13",
106
121
  "tsc-watch": "^7.1.1",
107
122
  "typescript": "^5.9.2",
123
+ "typescript-eslint": "^8.41.0",
108
124
  "vitest": "^3.2.4"
109
125
  },
110
126
  "peerDependencies": {
@@ -112,19 +128,5 @@
112
128
  "react": ">=16.14.0",
113
129
  "react-dom": ">=16.14.0",
114
130
  "react-router-dom": ">=6.26.2"
115
- },
116
- "scripts": {
117
- "tsc": "tsc --declaration",
118
- "build": "rslib build",
119
- "build:storybook": "storybook build",
120
- "bump": "changeset version",
121
- "change": "changeset",
122
- "check": "biome check --write",
123
- "dev": "rslib build --watch",
124
- "format": "biome format --write",
125
- "storybook": "storybook dev",
126
- "test": "echo 0",
127
- "lint": "eslint src --ext .js,.jsx,.ts,.tsx",
128
- "lint:fix": "eslint src --ext .js,.jsx,.ts,.tsx --fix"
129
131
  }
130
- }
132
+ }