@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.
- package/lib/components/TopNav/TitleBar.js +2 -2
- package/lib/hooks/useCurrentUserProfile.js +10 -10
- package/lib/hooks/useLogout.js +2 -2
- package/lib/integrations/generateImage.js +2 -2
- package/lib/integrations/generateTextStream.js +2 -2
- package/lib/integrations/getAppInfo.js +2 -2
- package/lib/utils/getUserProfile.js +2 -2
- package/lib/utils/utils.d.ts +1 -1
- package/lib/utils/utils.js +3 -3
- package/package.json +1 -1
@@ -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,
|
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 (
|
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 {
|
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 (
|
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
|
25
|
-
email: userInfo
|
26
|
-
name: userInfo
|
27
|
-
avatar: userInfo
|
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
|
38
|
-
email: userInfo
|
39
|
-
name: userInfo
|
40
|
-
avatar: userInfo
|
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
|
};
|
package/lib/hooks/useLogout.js
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
import { useState } from "react";
|
2
2
|
import { getDataloom } from "../integrations/dataloom.js";
|
3
|
-
import {
|
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 (
|
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 {
|
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 (
|
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 {
|
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 (
|
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 {
|
2
|
+
import { isSparkRuntime } from "../utils/utils.js";
|
3
3
|
async function getAppInfo() {
|
4
4
|
let appInfo = window._appInfo;
|
5
|
-
if (!appInfo &&
|
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 {
|
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 (
|
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`;
|
package/lib/utils/utils.d.ts
CHANGED
package/lib/utils/utils.js
CHANGED
@@ -10,7 +10,7 @@ function normalizeBasePath(basePath) {
|
|
10
10
|
if (!basePath || '/' === basePath) return '';
|
11
11
|
return basePath.replace(/\/+$/, '');
|
12
12
|
}
|
13
|
-
function
|
14
|
-
return window._IS_Spark_RUNTIME
|
13
|
+
function isSparkRuntime() {
|
14
|
+
return window._IS_Spark_RUNTIME ?? 'true' === process.env.fullstack;
|
15
15
|
}
|
16
|
-
export { clsxWithTw, isPreview,
|
16
|
+
export { clsxWithTw, isPreview, isSparkRuntime, normalizeBasePath };
|