@lark-apaas/client-toolkit 1.2.10-alpha.34 → 1.2.10-alpha.35
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/AppContainer/index.js +32 -5
- package/lib/components/AppContainer/safety.js +5 -2
- package/lib/components/AppContainer/utils/getLarkUser.js +4 -2
- package/lib/components/AppContainer/utils/observable.js +7 -1
- package/lib/components/theme/index.d.ts +1 -0
- package/lib/components/theme/index.js +1 -0
- package/lib/components/theme/ui-config.d.ts +1 -0
- package/lib/components/theme/ui-config.js +2 -0
- package/lib/components/theme/util.d.ts +2 -0
- package/lib/components/theme/util.js +108 -0
- package/lib/hooks/useLogout.js +2 -17
- package/lib/index.js +7 -0
- package/lib/integrations/dataloom.js +1 -1
- package/lib/integrations/services/DepartmentService.js +3 -2
- package/lib/integrations/services/UserProfileService.js +3 -2
- package/lib/integrations/services/UserService.js +4 -3
- package/lib/runtime/index.d.ts +0 -1
- package/lib/runtime/index.js +0 -1
- package/lib/utils/apiPath.d.ts +5 -0
- package/lib/utils/apiPath.js +5 -0
- package/lib/utils/getAppId.d.ts +2 -4
- package/lib/utils/getAppId.js +2 -9
- package/lib/utils/getInitialInfo.js +4 -2
- package/lib/utils/getUserProfile.js +4 -12
- package/lib/utils/scopedStorage.js +1 -1
- package/package.json +5 -5
- package/lib/apis/tools/generateImage.d.ts +0 -1
- package/lib/apis/tools/generateImage.js +0 -1
- package/lib/apis/tools/generateTextStream.d.ts +0 -1
- package/lib/apis/tools/generateTextStream.js +0 -1
- package/lib/integrations/generateImage.d.ts +0 -1
- package/lib/integrations/generateImage.js +0 -47
- package/lib/integrations/generateTextStream.d.ts +0 -21
- package/lib/integrations/generateTextStream.js +0 -98
- package/lib/runtime/react-devtools-hook.d.ts +0 -14
- package/lib/runtime/react-devtools-hook.js +0 -11
|
@@ -4,13 +4,16 @@ import { ConfigProvider } from "antd";
|
|
|
4
4
|
import { MiaodaInspector } from "@lark-apaas/miaoda-inspector";
|
|
5
5
|
import zh_CN from "antd/locale/zh_CN";
|
|
6
6
|
import IframeBridge from "./IframeBridge.js";
|
|
7
|
+
import { defaultUIConfig } from "../theme/ui-config.js";
|
|
7
8
|
import { Toaster } from "./sonner.js";
|
|
8
9
|
import { PageHoc } from "./PageHoc.js";
|
|
10
|
+
import { findValueByPixel, generateTailwindRadiusToken, themeColorTokenMap, themeMetaOptions } from "../theme/index.js";
|
|
9
11
|
import { reportTeaEvent } from "./utils/tea.js";
|
|
10
12
|
import { useAppInfo } from "../../hooks/index.js";
|
|
11
13
|
import { TrackKey } from "../../types/tea.js";
|
|
12
14
|
import safety from "./safety.js";
|
|
13
15
|
import { getAppId } from "../../utils/getAppId.js";
|
|
16
|
+
import { isNewPathEnabled } from "../../utils/apiPath.js";
|
|
14
17
|
import QueryProvider from "../QueryProvider/index.js";
|
|
15
18
|
import { AuthProvider } from "@lark-apaas/auth-sdk";
|
|
16
19
|
import "../../runtime/index.js";
|
|
@@ -25,8 +28,19 @@ const readCssVarColor = (varName, fallback)=>{
|
|
|
25
28
|
}
|
|
26
29
|
};
|
|
27
30
|
const App = (props)=>{
|
|
28
|
-
const { enableAuth } = props;
|
|
31
|
+
const { themeMeta = {}, enableAuth } = props;
|
|
29
32
|
useAppInfo();
|
|
33
|
+
const { rem } = findValueByPixel(themeMetaOptions.themeRadius, themeMeta.borderRadius) || {
|
|
34
|
+
rem: '0.625'
|
|
35
|
+
};
|
|
36
|
+
const radiusToken = generateTailwindRadiusToken(Number(rem));
|
|
37
|
+
const themeToken = {
|
|
38
|
+
...defaultUIConfig,
|
|
39
|
+
common: {
|
|
40
|
+
...defaultUIConfig.common,
|
|
41
|
+
borderRadius: radiusToken
|
|
42
|
+
}
|
|
43
|
+
};
|
|
30
44
|
useEffect(()=>{
|
|
31
45
|
if (isMiaodaPreview) fetch(`${location.origin}/ai/api/feida_preview/csrf`).then(()=>{
|
|
32
46
|
setTimeout(()=>{
|
|
@@ -39,19 +53,31 @@ const App = (props)=>{
|
|
|
39
53
|
if ('production' === process.env.NODE_ENV) reportTeaEvent({
|
|
40
54
|
trackKey: TrackKey.VIEW,
|
|
41
55
|
trackParams: {
|
|
42
|
-
artifact_uid: getAppId(
|
|
56
|
+
artifact_uid: getAppId(),
|
|
43
57
|
agent_id: 'agent_miaoda',
|
|
44
58
|
url: window.location.href
|
|
45
59
|
}
|
|
46
60
|
});
|
|
47
61
|
}, []);
|
|
62
|
+
const appId = getAppId();
|
|
63
|
+
const permissionApiUrl = isNewPathEnabled() ? `/app/${appId}/__runtime__/api/v1/permissions/roles` : `/spark/app/${appId}/runtime/api/v1/permissions/roles`;
|
|
48
64
|
return /*#__PURE__*/ jsxs(AuthProvider, {
|
|
49
65
|
config: {
|
|
50
|
-
enable: enableAuth
|
|
66
|
+
enable: enableAuth,
|
|
67
|
+
permissionApi: {
|
|
68
|
+
url: permissionApiUrl
|
|
69
|
+
}
|
|
51
70
|
},
|
|
52
71
|
children: [
|
|
53
72
|
/*#__PURE__*/ jsx(Toaster, {}),
|
|
54
|
-
'production' !== process.env.NODE_ENV && /*#__PURE__*/ jsx(MiaodaInspector, {
|
|
73
|
+
'production' !== process.env.NODE_ENV && /*#__PURE__*/ jsx(MiaodaInspector, {
|
|
74
|
+
theme: {
|
|
75
|
+
themeMetaOptions: themeMetaOptions,
|
|
76
|
+
themeColorTokenMap: themeColorTokenMap,
|
|
77
|
+
themeToken
|
|
78
|
+
},
|
|
79
|
+
cwd: process.env.CWD || ''
|
|
80
|
+
}),
|
|
55
81
|
'production' !== process.env.NODE_ENV && /*#__PURE__*/ jsx(IframeBridge, {}),
|
|
56
82
|
/*#__PURE__*/ jsx(PageHoc, {
|
|
57
83
|
children: props.children
|
|
@@ -60,7 +86,7 @@ const App = (props)=>{
|
|
|
60
86
|
});
|
|
61
87
|
};
|
|
62
88
|
const AppContainer_AppContainer = (props)=>{
|
|
63
|
-
const { children } = props;
|
|
89
|
+
const { children, ...rest } = props;
|
|
64
90
|
const [cssColors, setCssColors] = useState(()=>({
|
|
65
91
|
background: readCssVarColor('--background'),
|
|
66
92
|
destructive: readCssVarColor('--destructive'),
|
|
@@ -188,6 +214,7 @@ const AppContainer_AppContainer = (props)=>{
|
|
|
188
214
|
}
|
|
189
215
|
},
|
|
190
216
|
children: /*#__PURE__*/ jsx(App, {
|
|
217
|
+
themeMeta: props.themeMeta,
|
|
191
218
|
enableAuth: props.enableAuth,
|
|
192
219
|
children: children
|
|
193
220
|
})
|
|
@@ -3,11 +3,12 @@ import { useEffect, useRef, useState } from "react";
|
|
|
3
3
|
import { Popover, PopoverContent, PopoverTrigger } from "../ui/popover.js";
|
|
4
4
|
import { getCsrfToken } from "../../utils/getCsrfToken.js";
|
|
5
5
|
import { getAppId } from "../../utils/getAppId.js";
|
|
6
|
+
import { isNewPathEnabled } from "../../utils/apiPath.js";
|
|
6
7
|
import { useIsMobile } from "../../hooks/index.js";
|
|
7
8
|
import { X } from "lucide-react";
|
|
8
9
|
import { Sheet, SheetContent, SheetTrigger } from "../ui/drawer.js";
|
|
9
10
|
const Component = ()=>{
|
|
10
|
-
const HasClosedKey = `miaoda-creatByMiaoda-has-closed-${getAppId(
|
|
11
|
+
const HasClosedKey = `miaoda-creatByMiaoda-has-closed-${getAppId()}`;
|
|
11
12
|
const [visible, setVisible] = useState(!window.localStorage?.getItem(HasClosedKey));
|
|
12
13
|
const [open, setOpen] = useState(false);
|
|
13
14
|
const isMobile = useIsMobile();
|
|
@@ -15,7 +16,9 @@ const Component = ()=>{
|
|
|
15
16
|
const [isInternetVisible, setIsInternetVisible] = useState(false);
|
|
16
17
|
const timeoutRef = useRef(null);
|
|
17
18
|
useEffect(()=>{
|
|
18
|
-
|
|
19
|
+
const appId = getAppId();
|
|
20
|
+
const tenantInfoUrl = isNewPathEnabled() ? `/app/${appId}/__runtime__/api/v1/studio/tenant_info` : `/spark/b/${appId}/tenant_info`;
|
|
21
|
+
fetch(tenantInfoUrl, {
|
|
19
22
|
headers: {
|
|
20
23
|
'X-Suda-Csrf-Token': getCsrfToken()
|
|
21
24
|
}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { getAppId } from "../../../utils/getAppId.js";
|
|
2
2
|
import { getCsrfToken } from "../../../utils/getCsrfToken.js";
|
|
3
|
+
import { isNewPathEnabled } from "../../../utils/apiPath.js";
|
|
3
4
|
async function getLarkUserInfo() {
|
|
4
|
-
const appId = getAppId(
|
|
5
|
+
const appId = getAppId();
|
|
5
6
|
if (!appId) return {
|
|
6
7
|
code: 1,
|
|
7
8
|
msg: 'appId is required',
|
|
8
9
|
data: {}
|
|
9
10
|
};
|
|
10
|
-
const
|
|
11
|
+
const url = isNewPathEnabled() ? `/app/${appId}/__runtime__/api/v1/studio/lark/user_info` : `/spark/b/${appId}/lark/user_info`;
|
|
12
|
+
const response = await fetch(url, {
|
|
11
13
|
headers: {
|
|
12
14
|
'X-Suda-Csrf-Token': getCsrfToken()
|
|
13
15
|
}
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { AppEnv, observable } from "@lark-apaas/observable-web";
|
|
2
|
+
import { isNewPathEnabled } from "../../../utils/apiPath.js";
|
|
2
3
|
const initObservable = ()=>{
|
|
3
4
|
try {
|
|
4
5
|
const appId = window.appId;
|
|
5
6
|
observable.start({
|
|
6
7
|
serviceName: "app",
|
|
7
8
|
env: 'development' === process.env.NODE_ENV ? AppEnv.Dev : AppEnv.Prod,
|
|
8
|
-
collectorUrl: {
|
|
9
|
+
collectorUrl: isNewPathEnabled() ? {
|
|
10
|
+
log: `/app/${appId}/__runtime__/api/v1/observability/logs/collect`,
|
|
11
|
+
trace: `/app/${appId}/__runtime__/api/v1/observability/traces/collect`,
|
|
12
|
+
metric: `/app/${appId}/__runtime__/api/v1/observability/metrics/collect`,
|
|
13
|
+
time: `/app/${appId}/__runtime__/api/v1/observability/current_server_timestamp`
|
|
14
|
+
} : {
|
|
9
15
|
log: `/spark/app/${appId}/runtime/api/v1/observability/logs/collect`,
|
|
10
16
|
trace: `/spark/app/${appId}/runtime/api/v1/observability/traces/collect`,
|
|
11
17
|
metric: `/spark/app/${appId}/runtime/api/v1/observability/metrics/collect`,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { defaultUIConfig, type UIComponentConfig, } from '@lark-apaas/miaoda-inspector';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ITheme } from "../../types";
|
|
2
|
+
import { UIComponentConfig } from "./ui-config";
|
|
2
3
|
export interface IBaseThemeProviderProps {
|
|
3
4
|
defaultTheme?: ITheme;
|
|
4
5
|
themeMeta?: Partial<IThemeTokenMeta>;
|
|
@@ -17,3 +18,4 @@ export interface IThemeTokenMeta {
|
|
|
17
18
|
*/
|
|
18
19
|
spacing: number;
|
|
19
20
|
}
|
|
21
|
+
export declare const generateTailwindRadiusToken: (radiusRemValue: number) => UIComponentConfig;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
const generateTailwindRadiusToken = (radiusRemValue)=>{
|
|
2
|
+
try {
|
|
3
|
+
const rootFontSize = parseFloat(getComputedStyle(document.documentElement).fontSize);
|
|
4
|
+
const radiusPx = radiusRemValue * rootFontSize;
|
|
5
|
+
const tempElement = document.createElement('div');
|
|
6
|
+
tempElement.style.position = 'absolute';
|
|
7
|
+
tempElement.style.visibility = 'hidden';
|
|
8
|
+
document.body.appendChild(tempElement);
|
|
9
|
+
tempElement.style.borderRadius = `${radiusPx}px`;
|
|
10
|
+
const computed = getComputedStyle(tempElement).borderRadius;
|
|
11
|
+
document.body.removeChild(tempElement);
|
|
12
|
+
if (computed && 'auto' !== computed && 'initial' !== computed) return {
|
|
13
|
+
type: 'select',
|
|
14
|
+
options: [
|
|
15
|
+
{
|
|
16
|
+
value: 'rounded-none',
|
|
17
|
+
label: 'none(0px)',
|
|
18
|
+
rawValue: '0'
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
value: 'rounded-sm',
|
|
22
|
+
label: `sm (${Math.max(0, radiusPx - 4)}px)`,
|
|
23
|
+
rawValue: `${Math.max(0, radiusPx - 4)}`
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
value: 'rounded',
|
|
27
|
+
label: 's (4px)',
|
|
28
|
+
rawValue: '4'
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
value: 'rounded-md',
|
|
32
|
+
label: `m (${Math.max(0, radiusPx - 2)}px)`,
|
|
33
|
+
rawValue: `${Math.max(0, radiusPx - 2)}`
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
value: 'rounded-lg',
|
|
37
|
+
label: `l (${radiusPx}px)`,
|
|
38
|
+
rawValue: `${radiusPx}`
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
value: 'rounded-xl',
|
|
42
|
+
label: `xl (${radiusPx + 4}px)`,
|
|
43
|
+
rawValue: `${radiusPx + 4}`
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
value: 'rounded-2xl',
|
|
47
|
+
label: '2xl (16px)',
|
|
48
|
+
rawValue: '16'
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
value: 'rounded-full',
|
|
52
|
+
label: 'Full',
|
|
53
|
+
rawValue: '9999'
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
};
|
|
57
|
+
throw new Error('Browser calculation validation failed');
|
|
58
|
+
} catch (error) {
|
|
59
|
+
console.warn('Failed to get computed values from browser, falling back to default calculation:', error);
|
|
60
|
+
const radiusPx = 16 * radiusRemValue;
|
|
61
|
+
return {
|
|
62
|
+
type: 'select',
|
|
63
|
+
options: [
|
|
64
|
+
{
|
|
65
|
+
value: 'rounded-none',
|
|
66
|
+
label: 'none(0px)',
|
|
67
|
+
rawValue: '0'
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
value: 'rounded-sm',
|
|
71
|
+
label: `sm (${Math.max(0, radiusPx - 4)}px)`,
|
|
72
|
+
rawValue: `${Math.max(0, radiusPx - 4)}`
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
value: 'rounded',
|
|
76
|
+
label: 's (4px)',
|
|
77
|
+
rawValue: '4'
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
value: 'rounded-md',
|
|
81
|
+
label: `m (${Math.max(0, radiusPx - 2)}px)`,
|
|
82
|
+
rawValue: `${Math.max(0, radiusPx - 2)}`
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
value: 'rounded-lg',
|
|
86
|
+
label: `l (${radiusPx}px)`,
|
|
87
|
+
rawValue: `${radiusPx}`
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
value: 'rounded-xl',
|
|
91
|
+
label: `xl (${radiusPx + 4}px)`,
|
|
92
|
+
rawValue: `${radiusPx + 4}`
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
value: 'rounded-2xl',
|
|
96
|
+
label: '2xl (16px)',
|
|
97
|
+
rawValue: '16'
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
value: 'rounded-full',
|
|
101
|
+
label: 'Full',
|
|
102
|
+
rawValue: '9999'
|
|
103
|
+
}
|
|
104
|
+
]
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
export { generateTailwindRadiusToken };
|
package/lib/hooks/useLogout.js
CHANGED
|
@@ -1,28 +1,13 @@
|
|
|
1
1
|
import { useState } from "react";
|
|
2
2
|
import { getDataloom } from "../integrations/dataloom.js";
|
|
3
|
-
import { isSparkRuntime } from "../utils/utils.js";
|
|
4
3
|
function useLogout() {
|
|
5
4
|
const [isLoading, setIsLoading] = useState(false);
|
|
6
5
|
async function handlerLogout() {
|
|
7
6
|
if ('production' !== process.env.NODE_ENV) return void console.log('只有生产环境才执行登出');
|
|
8
|
-
if (isSparkRuntime()) {
|
|
9
|
-
setIsLoading(true);
|
|
10
|
-
try {
|
|
11
|
-
const dataloom = await getDataloom();
|
|
12
|
-
await dataloom.service.session.signOut();
|
|
13
|
-
} catch (error) {
|
|
14
|
-
console.error('登出失败', error);
|
|
15
|
-
} finally{
|
|
16
|
-
setIsLoading(false);
|
|
17
|
-
}
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
7
|
setIsLoading(true);
|
|
21
8
|
try {
|
|
22
|
-
await
|
|
23
|
-
|
|
24
|
-
});
|
|
25
|
-
window.location.reload();
|
|
9
|
+
const dataloom = await getDataloom();
|
|
10
|
+
await dataloom.service.session.signOut();
|
|
26
11
|
} catch (error) {
|
|
27
12
|
console.error('登出失败', error);
|
|
28
13
|
} finally{
|
package/lib/index.js
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import { createClient } from "@lark-apaas/client-capability";
|
|
2
2
|
import { normalizeBasePath } from "./utils/utils.js";
|
|
3
|
+
import { getAppId } from "./utils/getAppId.js";
|
|
4
|
+
import { isNewPathEnabled } from "./utils/apiPath.js";
|
|
3
5
|
import { logger } from "./logger/index.js";
|
|
4
6
|
import { showToast } from "./components/ui/toast.js";
|
|
5
7
|
import { version } from "../package.json";
|
|
8
|
+
const _appId = getAppId();
|
|
9
|
+
const _acquireUploadUrl = isNewPathEnabled() ? `/app/${_appId}/__runtime__/api/v1/studio/plugins/tmp_files/acquire_upload_url` : "/af/api/v1/studio/plugins/tmp_files/acquire_upload_url";
|
|
10
|
+
const _acquireDownloadUrl = isNewPathEnabled() ? `/app/${_appId}/__runtime__/api/v1/studio/plugins/tmp_files/acquire_download_url` : "/af/api/v1/studio/plugins/tmp_files/acquire_download_url";
|
|
6
11
|
const capabilityClient = createClient({
|
|
7
12
|
baseURL: normalizeBasePath(process.env.CLIENT_BASE_PATH),
|
|
13
|
+
acquireUploadUrl: _acquireUploadUrl,
|
|
14
|
+
acquireDownloadUrl: _acquireDownloadUrl,
|
|
8
15
|
fetchOptions: {
|
|
9
16
|
headers: {
|
|
10
17
|
'X-Suda-Csrf-Token': window.csrfToken ?? ''
|
|
@@ -7,7 +7,7 @@ const createDataLoomClient = (url, pat)=>{
|
|
|
7
7
|
baseUrl: '',
|
|
8
8
|
workspace: ''
|
|
9
9
|
};
|
|
10
|
-
const appId = getAppId(
|
|
10
|
+
const appId = getAppId();
|
|
11
11
|
return createClient(baseUrl, pat, workspace, {
|
|
12
12
|
global: {
|
|
13
13
|
enableDataloomLog: 'production' !== process.env.NODE_ENV,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { getAppId } from "../../utils/getAppId.js";
|
|
2
|
+
import { isNewPathEnabled } from "../../utils/apiPath.js";
|
|
2
3
|
const DEFAULT_CONFIG = {
|
|
3
|
-
getAppId: ()=>getAppId(
|
|
4
|
-
searchDepartmentUrl: (appId)
|
|
4
|
+
getAppId: ()=>getAppId(),
|
|
5
|
+
searchDepartmentUrl: (appId)=>isNewPathEnabled() ? `/app/${appId}/__runtime__/api/v1/account/search_department` : `/af/app/${appId}/runtime/api/v1/account/search_department`
|
|
5
6
|
};
|
|
6
7
|
class DepartmentService {
|
|
7
8
|
config;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { getAppId } from "../../utils/getAppId.js";
|
|
2
|
+
import { isNewPathEnabled } from "../../utils/apiPath.js";
|
|
2
3
|
const CDN_HOST = 'https://lf3-static.bytednsdoc.com';
|
|
3
4
|
function getAssetsUrl(path) {
|
|
4
5
|
return `${CDN_HOST}${path}`;
|
|
5
6
|
}
|
|
6
7
|
const DEFAULT_CONFIG = {
|
|
7
|
-
getAppId: ()=>getAppId(
|
|
8
|
-
userProfileUrl: (appId)
|
|
8
|
+
getAppId: ()=>getAppId(),
|
|
9
|
+
userProfileUrl: (appId)=>isNewPathEnabled() ? `/app/${appId}/__runtime__/api/v1/account/user_profile` : `/af/app/${appId}/runtime/api/v1/account/user_profile`
|
|
9
10
|
};
|
|
10
11
|
class UserProfileService {
|
|
11
12
|
config;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { getAppId } from "../../utils/getAppId.js";
|
|
2
|
+
import { isNewPathEnabled } from "../../utils/apiPath.js";
|
|
2
3
|
const DEFAULT_CONFIG = {
|
|
3
|
-
getAppId: ()=>getAppId(
|
|
4
|
-
searchUserUrl: (appId)
|
|
5
|
-
listUsersUrl: (appId)
|
|
4
|
+
getAppId: ()=>getAppId(),
|
|
5
|
+
searchUserUrl: (appId)=>isNewPathEnabled() ? `/app/${appId}/__runtime__/api/v1/account/search_user` : `/af/app/${appId}/runtime/api/v1/account/search_user`,
|
|
6
|
+
listUsersUrl: (appId)=>isNewPathEnabled() ? `/app/${appId}/__runtime__/api/v1/account/list_users` : `/af/app/${appId}/runtime/api/v1/account/list_users`
|
|
6
7
|
};
|
|
7
8
|
class UserService {
|
|
8
9
|
config;
|
package/lib/runtime/index.d.ts
CHANGED
package/lib/runtime/index.js
CHANGED
package/lib/utils/getAppId.d.ts
CHANGED
package/lib/utils/getAppId.js
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
|
-
function getAppId(
|
|
2
|
-
if (window.MIAODA_APP_ID) return window.MIAODA_APP_ID;
|
|
3
|
-
let prefix;
|
|
4
|
-
prefix = path.includes('/ai/feida/runtime/') ? '/ai/feida/runtime/' : path.includes('/spark/r/') ? '/spark/r/' : '/ai/miaoda/';
|
|
1
|
+
function getAppId() {
|
|
5
2
|
const windowAppId = window.appId || null;
|
|
6
|
-
|
|
7
|
-
const remainder = path.substring(prefix.length);
|
|
8
|
-
const nextSlashIndex = remainder.indexOf('/');
|
|
9
|
-
if (-1 === nextSlashIndex) return remainder || windowAppId;
|
|
10
|
-
return remainder.substring(0, nextSlashIndex) || windowAppId;
|
|
3
|
+
return windowAppId;
|
|
11
4
|
}
|
|
12
5
|
export { getAppId };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getAppId } from "./getAppId.js";
|
|
2
2
|
import { getCsrfToken } from "./getCsrfToken.js";
|
|
3
|
+
import { isNewPathEnabled } from "./apiPath.js";
|
|
3
4
|
async function getAppPublished() {
|
|
4
5
|
try {
|
|
5
6
|
const headers = {
|
|
@@ -8,8 +9,9 @@ async function getAppPublished() {
|
|
|
8
9
|
'x-miaoda-token': window.MIAODA_BUILTIN_TTT,
|
|
9
10
|
'X-Suda-Csrf-Token': getCsrfToken()
|
|
10
11
|
};
|
|
11
|
-
const appId = getAppId(
|
|
12
|
-
const
|
|
12
|
+
const appId = getAppId();
|
|
13
|
+
const path = isNewPathEnabled() ? `/app/${appId}/__runtime__/api/v1/studio/get_published` : `/spark/b/${appId}/get_published`;
|
|
14
|
+
const url = `${window.location.origin}${path}`;
|
|
13
15
|
const response = await fetch(url, {
|
|
14
16
|
method: 'GET',
|
|
15
17
|
headers,
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { getAppId } from "./getAppId.js";
|
|
2
2
|
import { getCsrfToken } from "./getCsrfToken.js";
|
|
3
|
-
import {
|
|
4
|
-
import { isSparkRuntime } from "./utils.js";
|
|
3
|
+
import { isNewPathEnabled } from "./apiPath.js";
|
|
5
4
|
async function getUserProfile(request, headers = {}) {
|
|
6
|
-
const appId = getAppId(
|
|
5
|
+
const appId = getAppId();
|
|
7
6
|
if (!appId) return {
|
|
8
7
|
code: 1,
|
|
9
8
|
msg: 'appId is required',
|
|
@@ -15,17 +14,10 @@ async function getUserProfile(request, headers = {}) {
|
|
|
15
14
|
const mergedHeaders = {
|
|
16
15
|
...defaultHeaders,
|
|
17
16
|
...headers,
|
|
18
|
-
'X-Kunlun-Token': window.token,
|
|
19
|
-
'x-miaoda-token': window.MIAODA_BUILTIN_TTT,
|
|
20
|
-
'x-lgw-csrf-token': window.lgw_csrf_token,
|
|
21
17
|
...window.CSRF_HEADERS || {}
|
|
22
18
|
};
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
if (isSparkRuntime()) {
|
|
26
|
-
endpoint = `/spark/b/${appId}/user/profile`;
|
|
27
|
-
mergedHeaders['X-Suda-Csrf-Token'] = getCsrfToken();
|
|
28
|
-
} else endpoint = `/ai/api/${envPath}/v1/apps/${appId}/user/profile`;
|
|
19
|
+
const endpoint = isNewPathEnabled() ? `/app/${appId}/__runtime__/api/v1/studio/user/profile` : `/spark/b/${appId}/user/profile`;
|
|
20
|
+
mergedHeaders['X-Suda-Csrf-Token'] = getCsrfToken();
|
|
29
21
|
const response = await fetch(`${window.location.origin}${endpoint}`, {
|
|
30
22
|
method: 'POST',
|
|
31
23
|
headers: mergedHeaders,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-apaas/client-toolkit",
|
|
3
|
-
"version": "1.2.10-alpha.
|
|
3
|
+
"version": "1.2.10-alpha.35",
|
|
4
4
|
"types": "./lib/index.d.ts",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -93,10 +93,10 @@
|
|
|
93
93
|
"dependencies": {
|
|
94
94
|
"@ant-design/colors": "^7.2.1",
|
|
95
95
|
"@ant-design/cssinjs": "^1.24.0",
|
|
96
|
-
"@data-loom/js": "0.4.
|
|
97
|
-
"@lark-apaas/auth-sdk": "
|
|
98
|
-
"@lark-apaas/client-capability": "
|
|
99
|
-
"@lark-apaas/miaoda-inspector": "1.0.
|
|
96
|
+
"@data-loom/js": "0.4.7",
|
|
97
|
+
"@lark-apaas/auth-sdk": "0.1.0-alpha.52",
|
|
98
|
+
"@lark-apaas/client-capability": "0.1.3-alpha.11",
|
|
99
|
+
"@lark-apaas/miaoda-inspector": "^1.0.15",
|
|
100
100
|
"@lark-apaas/observable-web": "^1.0.1",
|
|
101
101
|
"@radix-ui/react-avatar": "^1.1.10",
|
|
102
102
|
"@radix-ui/react-popover": "^1.1.15",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '../../integrations/generateImage';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "../../integrations/generateImage.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '../../integrations/generateTextStream';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "../../integrations/generateTextStream.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function generateImage(prompt: string, size?: string, headers?: Record<string, string>): Promise<any>;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { getAppId } from "../utils/getAppId.js";
|
|
2
|
-
import { getCsrfToken } from "../utils/getCsrfToken.js";
|
|
3
|
-
import { getEnvPath } from "../utils/getEnvPath.js";
|
|
4
|
-
import { isSparkRuntime } from "../utils/utils.js";
|
|
5
|
-
async function generateImage(prompt, size = '1024x1024', headers = {}) {
|
|
6
|
-
const appId = getAppId(window.location.pathname);
|
|
7
|
-
if (!appId) return {
|
|
8
|
-
code: 1,
|
|
9
|
-
msg: 'appId is required',
|
|
10
|
-
data: {}
|
|
11
|
-
};
|
|
12
|
-
const defaultHeaders = {
|
|
13
|
-
'Content-Type': 'application/json'
|
|
14
|
-
};
|
|
15
|
-
const mergedHeaders = {
|
|
16
|
-
...defaultHeaders,
|
|
17
|
-
...headers,
|
|
18
|
-
'X-Kunlun-Token': window.token,
|
|
19
|
-
'x-miaoda-token': window.MIAODA_BUILTIN_TTT,
|
|
20
|
-
'x-lgw-csrf-token': window.lgw_csrf_token,
|
|
21
|
-
...window.CSRF_HEADERS || {}
|
|
22
|
-
};
|
|
23
|
-
if (isSparkRuntime()) {
|
|
24
|
-
mergedHeaders['X-Suda-Csrf-Token'] = getCsrfToken();
|
|
25
|
-
const response = await fetch(`${window.location.origin}/spark/b/${appId}/text2image`, {
|
|
26
|
-
method: 'POST',
|
|
27
|
-
headers: mergedHeaders,
|
|
28
|
-
credentials: 'include',
|
|
29
|
-
body: JSON.stringify({
|
|
30
|
-
prompt,
|
|
31
|
-
size
|
|
32
|
-
})
|
|
33
|
-
});
|
|
34
|
-
return await response.json();
|
|
35
|
-
}
|
|
36
|
-
const response = await fetch(`${window.location.origin}/ai/api/${getEnvPath()}/v1/apps/${appId}/text2image`, {
|
|
37
|
-
method: 'POST',
|
|
38
|
-
headers: mergedHeaders,
|
|
39
|
-
credentials: 'include',
|
|
40
|
-
body: JSON.stringify({
|
|
41
|
-
prompt,
|
|
42
|
-
size
|
|
43
|
-
})
|
|
44
|
-
});
|
|
45
|
-
return await response.json();
|
|
46
|
-
}
|
|
47
|
-
export { generateImage };
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
interface GenerateTextOptions {
|
|
2
|
-
text: string;
|
|
3
|
-
thinking_type?: 'enabled' | 'disabled';
|
|
4
|
-
headers?: Record<string, string>;
|
|
5
|
-
}
|
|
6
|
-
interface GenerateTextResult {
|
|
7
|
-
content: string;
|
|
8
|
-
reasoning_content: string;
|
|
9
|
-
success: boolean;
|
|
10
|
-
error?: string;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* 文生文 - 流式版本
|
|
14
|
-
* 支持实时接收生成内容的回调
|
|
15
|
-
*/
|
|
16
|
-
export declare function generateTextStream(options: GenerateTextOptions, onChunk?: (chunk: {
|
|
17
|
-
content: string;
|
|
18
|
-
reasoning_content: string;
|
|
19
|
-
finished: boolean;
|
|
20
|
-
}) => void): Promise<GenerateTextResult>;
|
|
21
|
-
export {};
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { getAppId } from "../utils/getAppId.js";
|
|
2
|
-
import { getCsrfToken } from "../utils/getCsrfToken.js";
|
|
3
|
-
import { getEnvPath } from "../utils/getEnvPath.js";
|
|
4
|
-
import { isSparkRuntime } from "../utils/utils.js";
|
|
5
|
-
async function generateTextStream(options, onChunk) {
|
|
6
|
-
const { text, thinking_type = 'disabled', headers = {} } = options;
|
|
7
|
-
const appId = getAppId(window.location.pathname);
|
|
8
|
-
if (!appId) return {
|
|
9
|
-
content: '',
|
|
10
|
-
reasoning_content: '',
|
|
11
|
-
success: false,
|
|
12
|
-
error: 'appId is required'
|
|
13
|
-
};
|
|
14
|
-
try {
|
|
15
|
-
const mergedHeaders = {
|
|
16
|
-
'Content-Type': 'application/json',
|
|
17
|
-
...headers,
|
|
18
|
-
'X-Kunlun-Token': window.token,
|
|
19
|
-
'x-miaoda-token': window.MIAODA_BUILTIN_TTT,
|
|
20
|
-
'x-lgw-csrf-token': window.lgw_csrf_token,
|
|
21
|
-
...window.CSRF_HEADERS || {}
|
|
22
|
-
};
|
|
23
|
-
let response;
|
|
24
|
-
if (isSparkRuntime()) {
|
|
25
|
-
mergedHeaders['X-Suda-Csrf-Token'] = getCsrfToken();
|
|
26
|
-
response = await fetch(`${window.location.origin}/spark/b/${appId}/text/generate`, {
|
|
27
|
-
method: 'POST',
|
|
28
|
-
headers: mergedHeaders,
|
|
29
|
-
credentials: 'include',
|
|
30
|
-
body: JSON.stringify({
|
|
31
|
-
text,
|
|
32
|
-
thinking_type
|
|
33
|
-
})
|
|
34
|
-
});
|
|
35
|
-
} else response = await fetch(`${window.location.origin}/ai/api/${getEnvPath()}/v1/apps/${appId}/text/generate`, {
|
|
36
|
-
method: 'POST',
|
|
37
|
-
headers: mergedHeaders,
|
|
38
|
-
credentials: 'include',
|
|
39
|
-
body: JSON.stringify({
|
|
40
|
-
text,
|
|
41
|
-
thinking_type
|
|
42
|
-
})
|
|
43
|
-
});
|
|
44
|
-
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
|
|
45
|
-
const reader = response.body?.getReader();
|
|
46
|
-
if (!reader) throw new Error('无法获取响应流');
|
|
47
|
-
let fullContent = '';
|
|
48
|
-
let fullReasoningContent = '';
|
|
49
|
-
const decoder = new TextDecoder();
|
|
50
|
-
while(true){
|
|
51
|
-
const { done, value } = await reader.read();
|
|
52
|
-
if (done) break;
|
|
53
|
-
const chunk = decoder.decode(value, {
|
|
54
|
-
stream: true
|
|
55
|
-
});
|
|
56
|
-
const lines = chunk.split('\n').filter((line)=>line.trim());
|
|
57
|
-
for (const line of lines)if (line.startsWith('data: ')) {
|
|
58
|
-
const jsonStr = line.slice(6);
|
|
59
|
-
try {
|
|
60
|
-
const data = JSON.parse(jsonStr);
|
|
61
|
-
if (0 !== data.code) return {
|
|
62
|
-
content: '',
|
|
63
|
-
reasoning_content: '',
|
|
64
|
-
success: false,
|
|
65
|
-
error: data.msg || '生成失败'
|
|
66
|
-
};
|
|
67
|
-
if (data.data.content) fullContent += data.data.content;
|
|
68
|
-
if (data.data.reasoning_content) fullReasoningContent += data.data.reasoning_content;
|
|
69
|
-
if (onChunk) onChunk({
|
|
70
|
-
content: data.data.content || '',
|
|
71
|
-
reasoning_content: data.data.reasoning_content || '',
|
|
72
|
-
finished: data.finished
|
|
73
|
-
});
|
|
74
|
-
if (data.finished) return {
|
|
75
|
-
content: fullContent,
|
|
76
|
-
reasoning_content: fullReasoningContent,
|
|
77
|
-
success: true
|
|
78
|
-
};
|
|
79
|
-
} catch (parseError) {
|
|
80
|
-
console.error(`解析JSON失败: ${jsonStr}`);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
return {
|
|
85
|
-
content: fullContent,
|
|
86
|
-
reasoning_content: fullReasoningContent,
|
|
87
|
-
success: true
|
|
88
|
-
};
|
|
89
|
-
} catch (error) {
|
|
90
|
-
return {
|
|
91
|
-
content: '',
|
|
92
|
-
reasoning_content: '',
|
|
93
|
-
success: false,
|
|
94
|
-
error: error instanceof Error ? error.message : '未知错误'
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
export { generateTextStream };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Inject minimal __REACT_DEVTOOLS_GLOBAL_HOOK__ before React loads.
|
|
3
|
-
* React checks for this hook during module initialization and registers its
|
|
4
|
-
* renderer via hook.inject(). This gives us access to renderer.overrideProps()
|
|
5
|
-
* for live component prop modification in the inspector.
|
|
6
|
-
*
|
|
7
|
-
* Must execute before React's module-level code runs.
|
|
8
|
-
*/
|
|
9
|
-
export {};
|
|
10
|
-
declare global {
|
|
11
|
-
interface Window {
|
|
12
|
-
__REACT_DEVTOOLS_GLOBAL_HOOK__?: any;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
if ('undefined' != typeof window && !window.__REACT_DEVTOOLS_GLOBAL_HOOK__) window.__REACT_DEVTOOLS_GLOBAL_HOOK__ = {
|
|
2
|
-
renderers: new Map(),
|
|
3
|
-
supportsFiber: true,
|
|
4
|
-
inject (renderer) {
|
|
5
|
-
const id = this.renderers.size + 1;
|
|
6
|
-
this.renderers.set(id, renderer);
|
|
7
|
-
return id;
|
|
8
|
-
},
|
|
9
|
-
onCommitFiberRoot () {},
|
|
10
|
-
onCommitFiberUnmount () {}
|
|
11
|
-
};
|