@lark-apaas/miaoda-core 0.1.0-alpha.20 → 0.1.0-alpha.21

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.
@@ -2,7 +2,7 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
2
  import { useMemo, useState } from "react";
3
3
  import { Link, matchPath, useLocation } from "react-router-dom";
4
4
  import { LogOut, MoreHorizontal, X } from "lucide-react";
5
- import { clsxWithTw, isSanboxMode } from "../../utils/utils.js";
5
+ import { clsxWithTw, isSparkRuntime } from "../../utils/utils.js";
6
6
  import { useAppInfo, useCurrentUserProfile, useLogout } from "../../hooks/index.js";
7
7
  import { DropdownThemeClass, MaskThemeClass, TopHeaderThemeClass } from "../common/index.js";
8
8
  const TitleBar = ({ navList, className })=>{
@@ -91,7 +91,7 @@ const TitleBar = ({ navList, className })=>{
91
91
  }),
92
92
  /*#__PURE__*/ jsx("img", {
93
93
  onClick: ()=>{
94
- if (isSanboxMode()) location.href = '/suda/user?brand=1';
94
+ if (isSparkRuntime()) location.href = '/suda/user?brand=1';
95
95
  },
96
96
  src: userAvatar,
97
97
  alt: "avatar",
@@ -2,7 +2,7 @@ import { useEffect, useState } from "react";
2
2
  import { logger } from "../logger/index.js";
3
3
  import { getCurrentUserProfile } from "../integrations/getCurrentUserProfile.js";
4
4
  import { getDataloom } from "../integrations/dataloom.js";
5
- import { isSanboxMode } from "../utils/utils.js";
5
+ import { isSparkRuntime } from "../utils/utils.js";
6
6
  function getCompatibilityUserProfile() {
7
7
  const userInfo = getCurrentUserProfile();
8
8
  return {
@@ -15,16 +15,16 @@ const useCurrentUserProfile = ()=>{
15
15
  const [userInfo, setUserInfo] = useState(()=>getCompatibilityUserProfile());
16
16
  useEffect(()=>{
17
17
  let handleMetaInfoChanged;
18
- if (isSanboxMode()) {
18
+ if (isSparkRuntime()) {
19
19
  (async ()=>{
20
20
  const dataloom = await getDataloom();
21
21
  const result = await dataloom.service.session.getUserInfo();
22
22
  const userInfo = result?.data?.user_info;
23
23
  setUserInfo({
24
- user_id: userInfo.user_id?.toString(),
25
- email: userInfo.email,
26
- name: userInfo.name?.[0]?.text,
27
- avatar: userInfo.avatar?.image?.large,
24
+ user_id: userInfo?.user_id?.toString(),
25
+ email: userInfo?.email,
26
+ name: userInfo?.name?.[0]?.text,
27
+ avatar: userInfo?.avatar?.image?.large,
28
28
  userName: userInfo?.name?.[0]?.text,
29
29
  userAvatar: userInfo?.avatar?.image?.large
30
30
  });
@@ -34,10 +34,10 @@ const useCurrentUserProfile = ()=>{
34
34
  const result = await dataloom.service.session.getUserInfo();
35
35
  const userInfo = result?.data?.user_info;
36
36
  const newUserInfo = {
37
- user_id: userInfo.user_id?.toString(),
38
- email: userInfo.email,
39
- name: userInfo.name?.[0]?.text,
40
- avatar: userInfo.avatar?.image?.large,
37
+ user_id: userInfo?.user_id?.toString(),
38
+ email: userInfo?.email,
39
+ name: userInfo?.name?.[0]?.text,
40
+ avatar: userInfo?.avatar?.image?.large,
41
41
  userName: userInfo?.name?.[0]?.text,
42
42
  userAvatar: userInfo?.avatar?.image?.large
43
43
  };
@@ -1,11 +1,11 @@
1
1
  import { useState } from "react";
2
2
  import { getDataloom } from "../integrations/dataloom.js";
3
- import { isSanboxMode } from "../utils/utils.js";
3
+ import { isSparkRuntime } from "../utils/utils.js";
4
4
  function useLogout() {
5
5
  const [isLoading, setIsLoading] = useState(false);
6
6
  async function handlerLogout() {
7
7
  if ('production' !== process.env.NODE_ENV) return void console.log('只有生产环境才执行登出');
8
- if (isSanboxMode()) {
8
+ if (isSparkRuntime()) {
9
9
  setIsLoading(true);
10
10
  try {
11
11
  const dataloom = await getDataloom();
@@ -1,7 +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
+ import { isSparkRuntime } from "../utils/utils.js";
5
5
  async function generateImage(prompt, size = '1024x1024', headers = {}) {
6
6
  const appId = getAppId(window.location.pathname);
7
7
  if (!appId) return {
@@ -20,7 +20,7 @@ async function generateImage(prompt, size = '1024x1024', headers = {}) {
20
20
  'x-lgw-csrf-token': window.lgw_csrf_token,
21
21
  ...window.CSRF_HEADERS || {}
22
22
  };
23
- if (isSanboxMode()) {
23
+ if (isSparkRuntime()) {
24
24
  mergedHeaders['X-Suda-Csrf-Token'] = getCsrfToken();
25
25
  const response = await fetch(`${window.location.origin}/spark/b/${appId}/text2image`, {
26
26
  method: 'POST',
@@ -1,7 +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
+ import { isSparkRuntime } from "../utils/utils.js";
5
5
  async function generateTextStream(options, onChunk) {
6
6
  const { text, thinking_type = 'disabled', headers = {} } = options;
7
7
  const appId = getAppId(window.location.pathname);
@@ -21,7 +21,7 @@ async function generateTextStream(options, onChunk) {
21
21
  ...window.CSRF_HEADERS || {}
22
22
  };
23
23
  let response;
24
- if (isSanboxMode()) {
24
+ if (isSparkRuntime()) {
25
25
  mergedHeaders['X-Suda-Csrf-Token'] = getCsrfToken();
26
26
  response = await fetch(`${window.location.origin}/spark/b/${appId}/text/generate`, {
27
27
  method: 'POST',
@@ -1,8 +1,8 @@
1
1
  import { getInitialInfo } from "../utils/getInitialInfo.js";
2
- import { isSanboxMode } from "../utils/utils.js";
2
+ import { isSparkRuntime } from "../utils/utils.js";
3
3
  async function getAppInfo() {
4
4
  let appInfo = window._appInfo;
5
- if (!appInfo && isSanboxMode()) {
5
+ if (!appInfo && isSparkRuntime()) {
6
6
  const info = (await getInitialInfo()).app_info;
7
7
  appInfo = {
8
8
  name: info?.app_name || '',
@@ -1,7 +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
+ import { isSparkRuntime } from "./utils.js";
5
5
  async function getUserProfile(request, headers = {}) {
6
6
  const appId = getAppId(window.location.pathname);
7
7
  if (!appId) return {
@@ -22,7 +22,7 @@ async function getUserProfile(request, headers = {}) {
22
22
  };
23
23
  const envPath = getEnvPath();
24
24
  let endpoint;
25
- if (isSanboxMode()) {
25
+ if (isSparkRuntime()) {
26
26
  endpoint = `/spark/b/${appId}/user/profile`;
27
27
  mergedHeaders['X-Suda-Csrf-Token'] = getCsrfToken();
28
28
  } else endpoint = `/ai/api/${envPath}/v1/apps/${appId}/user/profile`;
@@ -16,4 +16,4 @@ export declare function isPreview(): boolean;
16
16
  */
17
17
  export declare function normalizeBasePath(basePath?: string): string;
18
18
  /** 判断是否是沙箱模式 */
19
- export declare function isSanboxMode(): any;
19
+ export declare function isSparkRuntime(): boolean;
@@ -10,7 +10,7 @@ function normalizeBasePath(basePath) {
10
10
  if (!basePath || '/' === basePath) return '';
11
11
  return basePath.replace(/\/+$/, '');
12
12
  }
13
- function isSanboxMode() {
14
- return window._IS_Spark_RUNTIME || window.isSanboxMode;
13
+ function isSparkRuntime() {
14
+ return window._IS_Spark_RUNTIME ?? 'true' === process.env.fullstack;
15
15
  }
16
- export { clsxWithTw, isPreview, isSanboxMode, normalizeBasePath };
16
+ export { clsxWithTw, isPreview, isSparkRuntime, normalizeBasePath };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/miaoda-core",
3
- "version": "0.1.0-alpha.20",
3
+ "version": "0.1.0-alpha.21",
4
4
  "types": "./lib/index.d.ts",
5
5
  "main": "./lib/index.js",
6
6
  "files": [