@lark-apaas/client-toolkit 1.2.10-alpha.37 → 1.2.10-alpha.38
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/apis/tools/generateImage.d.ts +1 -0
- package/lib/apis/tools/generateImage.js +1 -0
- package/lib/apis/tools/generateTextStream.d.ts +1 -0
- package/lib/apis/tools/generateTextStream.js +1 -0
- package/lib/components/AppContainer/index.d.ts +5 -1
- package/lib/components/AppContainer/index.js +6 -10
- package/lib/components/AppContainer/safety.js +2 -5
- package/lib/components/AppContainer/utils/getLarkUser.js +2 -4
- package/lib/components/AppContainer/utils/observable.js +1 -7
- package/lib/hooks/useLogout.js +17 -2
- package/lib/index.js +0 -7
- package/lib/integrations/dataloom.js +1 -1
- package/lib/integrations/generateImage.d.ts +1 -0
- package/lib/integrations/generateImage.js +47 -0
- package/lib/integrations/generateTextStream.d.ts +21 -0
- package/lib/integrations/generateTextStream.js +98 -0
- package/lib/integrations/services/DepartmentService.js +2 -3
- package/lib/integrations/services/UserProfileService.js +2 -3
- package/lib/integrations/services/UserService.js +3 -4
- package/lib/integrations/services/types.d.ts +1 -0
- package/lib/utils/getAppId.d.ts +4 -2
- package/lib/utils/getAppId.js +9 -2
- package/lib/utils/getInitialInfo.js +2 -4
- package/lib/utils/getUserProfile.js +12 -4
- package/lib/utils/scopedStorage.js +1 -1
- package/package.json +4 -4
- package/lib/utils/apiPath.d.ts +0 -5
- package/lib/utils/apiPath.js +0 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../integrations/generateImage';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../../integrations/generateImage.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../integrations/generateTextStream';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../../integrations/generateTextStream.js";
|
|
@@ -4,7 +4,11 @@ import '../../runtime';
|
|
|
4
4
|
interface IBaseAuthProviderProps {
|
|
5
5
|
enableAuth?: boolean;
|
|
6
6
|
}
|
|
7
|
+
interface IToasterProps {
|
|
8
|
+
/** 禁用内建 Toaster 组件,默认 false */
|
|
9
|
+
disableToaster?: boolean;
|
|
10
|
+
}
|
|
7
11
|
declare const AppContainer: React.FC<{
|
|
8
12
|
children: React.ReactNode;
|
|
9
|
-
} & IBaseThemeProviderProps & IBaseAuthProviderProps>;
|
|
13
|
+
} & IBaseThemeProviderProps & IBaseAuthProviderProps & IToasterProps>;
|
|
10
14
|
export default AppContainer;
|
|
@@ -13,7 +13,6 @@ import { useAppInfo } from "../../hooks/index.js";
|
|
|
13
13
|
import { TrackKey } from "../../types/tea.js";
|
|
14
14
|
import safety from "./safety.js";
|
|
15
15
|
import { getAppId } from "../../utils/getAppId.js";
|
|
16
|
-
import { isNewPathEnabled } from "../../utils/apiPath.js";
|
|
17
16
|
import QueryProvider from "../QueryProvider/index.js";
|
|
18
17
|
import { AuthProvider } from "@lark-apaas/auth-sdk";
|
|
19
18
|
import "../../runtime/index.js";
|
|
@@ -27,8 +26,9 @@ const readCssVarColor = (varName, fallback)=>{
|
|
|
27
26
|
return fallback;
|
|
28
27
|
}
|
|
29
28
|
};
|
|
29
|
+
const appFlags = process.env.APP_FLAGS || {};
|
|
30
30
|
const App = (props)=>{
|
|
31
|
-
const { themeMeta = {}, enableAuth } = props;
|
|
31
|
+
const { themeMeta = {}, enableAuth, disableToaster = false } = props;
|
|
32
32
|
useAppInfo();
|
|
33
33
|
const { rem } = findValueByPixel(themeMetaOptions.themeRadius, themeMeta.borderRadius) || {
|
|
34
34
|
rem: '0.625'
|
|
@@ -53,23 +53,18 @@ const App = (props)=>{
|
|
|
53
53
|
if ('production' === process.env.NODE_ENV) reportTeaEvent({
|
|
54
54
|
trackKey: TrackKey.VIEW,
|
|
55
55
|
trackParams: {
|
|
56
|
-
artifact_uid: getAppId(),
|
|
56
|
+
artifact_uid: getAppId(window.location.pathname),
|
|
57
57
|
agent_id: 'agent_miaoda',
|
|
58
58
|
url: window.location.href
|
|
59
59
|
}
|
|
60
60
|
});
|
|
61
61
|
}, []);
|
|
62
|
-
const appId = getAppId();
|
|
63
|
-
const permissionApiUrl = isNewPathEnabled() ? `/app/${appId}/__runtime__/api/v1/permissions/roles` : `/spark/app/${appId}/runtime/api/v1/permissions/roles`;
|
|
64
62
|
return /*#__PURE__*/ jsxs(AuthProvider, {
|
|
65
63
|
config: {
|
|
66
|
-
enable: enableAuth
|
|
67
|
-
permissionApi: {
|
|
68
|
-
url: permissionApiUrl
|
|
69
|
-
}
|
|
64
|
+
enable: enableAuth
|
|
70
65
|
},
|
|
71
66
|
children: [
|
|
72
|
-
/*#__PURE__*/ jsx(Toaster, {}),
|
|
67
|
+
!disableToaster && true !== appFlags.customToaster && /*#__PURE__*/ jsx(Toaster, {}),
|
|
73
68
|
'production' !== process.env.NODE_ENV && /*#__PURE__*/ jsx(MiaodaInspector, {
|
|
74
69
|
theme: {
|
|
75
70
|
themeMetaOptions: themeMetaOptions,
|
|
@@ -216,6 +211,7 @@ const AppContainer_AppContainer = (props)=>{
|
|
|
216
211
|
children: /*#__PURE__*/ jsx(App, {
|
|
217
212
|
themeMeta: props.themeMeta,
|
|
218
213
|
enableAuth: props.enableAuth,
|
|
214
|
+
disableToaster: props.disableToaster,
|
|
219
215
|
children: children
|
|
220
216
|
})
|
|
221
217
|
})
|
|
@@ -3,12 +3,11 @@ 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";
|
|
7
6
|
import { useIsMobile } from "../../hooks/index.js";
|
|
8
7
|
import { X } from "lucide-react";
|
|
9
8
|
import { Sheet, SheetContent, SheetTrigger } from "../ui/drawer.js";
|
|
10
9
|
const Component = ()=>{
|
|
11
|
-
const HasClosedKey = `miaoda-creatByMiaoda-has-closed-${getAppId()}`;
|
|
10
|
+
const HasClosedKey = `miaoda-creatByMiaoda-has-closed-${getAppId(window.location.pathname)}`;
|
|
12
11
|
const [visible, setVisible] = useState(!window.localStorage?.getItem(HasClosedKey));
|
|
13
12
|
const [open, setOpen] = useState(false);
|
|
14
13
|
const isMobile = useIsMobile();
|
|
@@ -16,9 +15,7 @@ const Component = ()=>{
|
|
|
16
15
|
const [isInternetVisible, setIsInternetVisible] = useState(false);
|
|
17
16
|
const timeoutRef = useRef(null);
|
|
18
17
|
useEffect(()=>{
|
|
19
|
-
|
|
20
|
-
const tenantInfoUrl = isNewPathEnabled() ? `/app/${appId}/__runtime__/api/v1/studio/tenant_info` : `/spark/b/${appId}/tenant_info`;
|
|
21
|
-
fetch(tenantInfoUrl, {
|
|
18
|
+
fetch(`/spark/b/${getAppId(window.location.pathname)}/tenant_info`, {
|
|
22
19
|
headers: {
|
|
23
20
|
'X-Suda-Csrf-Token': getCsrfToken()
|
|
24
21
|
}
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import { getAppId } from "../../../utils/getAppId.js";
|
|
2
2
|
import { getCsrfToken } from "../../../utils/getCsrfToken.js";
|
|
3
|
-
import { isNewPathEnabled } from "../../../utils/apiPath.js";
|
|
4
3
|
async function getLarkUserInfo() {
|
|
5
|
-
const appId = getAppId();
|
|
4
|
+
const appId = getAppId(window.location.pathname);
|
|
6
5
|
if (!appId) return {
|
|
7
6
|
code: 1,
|
|
8
7
|
msg: 'appId is required',
|
|
9
8
|
data: {}
|
|
10
9
|
};
|
|
11
|
-
const
|
|
12
|
-
const response = await fetch(url, {
|
|
10
|
+
const response = await fetch(`/spark/b/${appId}/lark/user_info`, {
|
|
13
11
|
headers: {
|
|
14
12
|
'X-Suda-Csrf-Token': getCsrfToken()
|
|
15
13
|
}
|
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
import { AppEnv, observable } from "@lark-apaas/observable-web";
|
|
2
|
-
import { isNewPathEnabled } from "../../../utils/apiPath.js";
|
|
3
2
|
const initObservable = ()=>{
|
|
4
3
|
try {
|
|
5
4
|
const appId = window.appId;
|
|
6
5
|
observable.start({
|
|
7
6
|
serviceName: "app",
|
|
8
7
|
env: 'development' === process.env.NODE_ENV ? AppEnv.Dev : AppEnv.Prod,
|
|
9
|
-
collectorUrl:
|
|
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
|
-
} : {
|
|
8
|
+
collectorUrl: {
|
|
15
9
|
log: `/spark/app/${appId}/runtime/api/v1/observability/logs/collect`,
|
|
16
10
|
trace: `/spark/app/${appId}/runtime/api/v1/observability/traces/collect`,
|
|
17
11
|
metric: `/spark/app/${appId}/runtime/api/v1/observability/metrics/collect`,
|
package/lib/hooks/useLogout.js
CHANGED
|
@@ -1,13 +1,28 @@
|
|
|
1
1
|
import { useState } from "react";
|
|
2
2
|
import { getDataloom } from "../integrations/dataloom.js";
|
|
3
|
+
import { isSparkRuntime } from "../utils/utils.js";
|
|
3
4
|
function useLogout() {
|
|
4
5
|
const [isLoading, setIsLoading] = useState(false);
|
|
5
6
|
async function handlerLogout() {
|
|
6
7
|
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
|
+
}
|
|
7
20
|
setIsLoading(true);
|
|
8
21
|
try {
|
|
9
|
-
|
|
10
|
-
|
|
22
|
+
await fetch('/ai/api/ui/page/logout', {
|
|
23
|
+
method: 'GET'
|
|
24
|
+
});
|
|
25
|
+
window.location.reload();
|
|
11
26
|
} catch (error) {
|
|
12
27
|
console.error('登出失败', error);
|
|
13
28
|
} finally{
|
package/lib/index.js
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
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";
|
|
5
3
|
import { logger } from "./logger/index.js";
|
|
6
4
|
import { showToast } from "./components/ui/toast.js";
|
|
7
5
|
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";
|
|
11
6
|
const capabilityClient = createClient({
|
|
12
7
|
baseURL: normalizeBasePath(process.env.CLIENT_BASE_PATH),
|
|
13
|
-
acquireUploadUrl: _acquireUploadUrl,
|
|
14
|
-
acquireDownloadUrl: _acquireDownloadUrl,
|
|
15
8
|
fetchOptions: {
|
|
16
9
|
headers: {
|
|
17
10
|
'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(window.location.pathname);
|
|
11
11
|
return createClient(baseUrl, pat, workspace, {
|
|
12
12
|
global: {
|
|
13
13
|
enableDataloomLog: 'production' !== process.env.NODE_ENV,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function generateImage(prompt: string, size?: string, headers?: Record<string, string>): Promise<any>;
|
|
@@ -0,0 +1,47 @@
|
|
|
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 };
|
|
@@ -0,0 +1,21 @@
|
|
|
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 {};
|
|
@@ -0,0 +1,98 @@
|
|
|
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,8 +1,7 @@
|
|
|
1
1
|
import { getAppId } from "../../utils/getAppId.js";
|
|
2
|
-
import { isNewPathEnabled } from "../../utils/apiPath.js";
|
|
3
2
|
const DEFAULT_CONFIG = {
|
|
4
|
-
getAppId: ()=>getAppId(),
|
|
5
|
-
searchDepartmentUrl: (appId)
|
|
3
|
+
getAppId: ()=>getAppId(window.location.pathname),
|
|
4
|
+
searchDepartmentUrl: (appId)=>`/af/app/${appId}/runtime/api/v1/account/search_department`
|
|
6
5
|
};
|
|
7
6
|
class DepartmentService {
|
|
8
7
|
config;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { getAppId } from "../../utils/getAppId.js";
|
|
2
|
-
import { isNewPathEnabled } from "../../utils/apiPath.js";
|
|
3
2
|
const CDN_HOST = 'https://lf3-static.bytednsdoc.com';
|
|
4
3
|
function getAssetsUrl(path) {
|
|
5
4
|
return `${CDN_HOST}${path}`;
|
|
6
5
|
}
|
|
7
6
|
const DEFAULT_CONFIG = {
|
|
8
|
-
getAppId: ()=>getAppId(),
|
|
9
|
-
userProfileUrl: (appId)
|
|
7
|
+
getAppId: ()=>getAppId(window.location.pathname),
|
|
8
|
+
userProfileUrl: (appId)=>`/af/app/${appId}/runtime/api/v1/account/user_profile`
|
|
10
9
|
};
|
|
11
10
|
class UserProfileService {
|
|
12
11
|
config;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { getAppId } from "../../utils/getAppId.js";
|
|
2
|
-
import { isNewPathEnabled } from "../../utils/apiPath.js";
|
|
3
2
|
const DEFAULT_CONFIG = {
|
|
4
|
-
getAppId: ()=>getAppId(),
|
|
5
|
-
searchUserUrl: (appId)
|
|
6
|
-
listUsersUrl: (appId)
|
|
3
|
+
getAppId: ()=>getAppId(window.location.pathname),
|
|
4
|
+
searchUserUrl: (appId)=>`/af/app/${appId}/runtime/api/v1/account/search_user`,
|
|
5
|
+
listUsersUrl: (appId)=>`/af/app/${appId}/runtime/api/v1/account/list_users`
|
|
7
6
|
};
|
|
8
7
|
class UserService {
|
|
9
8
|
config;
|
package/lib/utils/getAppId.d.ts
CHANGED
package/lib/utils/getAppId.js
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
function getAppId() {
|
|
1
|
+
function getAppId(path) {
|
|
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/';
|
|
2
5
|
const windowAppId = window.appId || null;
|
|
3
|
-
return windowAppId;
|
|
6
|
+
if (!path.startsWith(prefix)) return windowAppId;
|
|
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;
|
|
4
11
|
}
|
|
5
12
|
export { getAppId };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { getAppId } from "./getAppId.js";
|
|
2
2
|
import { getCsrfToken } from "./getCsrfToken.js";
|
|
3
|
-
import { isNewPathEnabled } from "./apiPath.js";
|
|
4
3
|
async function getAppPublished() {
|
|
5
4
|
try {
|
|
6
5
|
const headers = {
|
|
@@ -9,9 +8,8 @@ async function getAppPublished() {
|
|
|
9
8
|
'x-miaoda-token': window.MIAODA_BUILTIN_TTT,
|
|
10
9
|
'X-Suda-Csrf-Token': getCsrfToken()
|
|
11
10
|
};
|
|
12
|
-
const appId = getAppId();
|
|
13
|
-
const
|
|
14
|
-
const url = `${window.location.origin}${path}`;
|
|
11
|
+
const appId = getAppId(window.location.pathname) || window.appId;
|
|
12
|
+
const url = `${window.location.origin}/spark/b/${appId}/get_published`;
|
|
15
13
|
const response = await fetch(url, {
|
|
16
14
|
method: 'GET',
|
|
17
15
|
headers,
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { getAppId } from "./getAppId.js";
|
|
2
2
|
import { getCsrfToken } from "./getCsrfToken.js";
|
|
3
|
-
import {
|
|
3
|
+
import { getEnvPath } from "./getEnvPath.js";
|
|
4
|
+
import { isSparkRuntime } from "./utils.js";
|
|
4
5
|
async function getUserProfile(request, headers = {}) {
|
|
5
|
-
const appId = getAppId();
|
|
6
|
+
const appId = getAppId(window.location.pathname);
|
|
6
7
|
if (!appId) return {
|
|
7
8
|
code: 1,
|
|
8
9
|
msg: 'appId is required',
|
|
@@ -14,10 +15,17 @@ async function getUserProfile(request, headers = {}) {
|
|
|
14
15
|
const mergedHeaders = {
|
|
15
16
|
...defaultHeaders,
|
|
16
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,
|
|
17
21
|
...window.CSRF_HEADERS || {}
|
|
18
22
|
};
|
|
19
|
-
const
|
|
20
|
-
|
|
23
|
+
const envPath = getEnvPath();
|
|
24
|
+
let endpoint;
|
|
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`;
|
|
21
29
|
const response = await fetch(`${window.location.origin}${endpoint}`, {
|
|
22
30
|
method: 'POST',
|
|
23
31
|
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.38",
|
|
4
4
|
"types": "./lib/index.d.ts",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -94,9 +94,9 @@
|
|
|
94
94
|
"@ant-design/colors": "^7.2.1",
|
|
95
95
|
"@ant-design/cssinjs": "^1.24.0",
|
|
96
96
|
"@data-loom/js": "0.4.7",
|
|
97
|
-
"@lark-apaas/auth-sdk": "0.1.0
|
|
98
|
-
"@lark-apaas/client-capability": "0.1.
|
|
99
|
-
"@lark-apaas/miaoda-inspector": "^1.0.
|
|
97
|
+
"@lark-apaas/auth-sdk": "^0.1.0",
|
|
98
|
+
"@lark-apaas/client-capability": "^0.1.4",
|
|
99
|
+
"@lark-apaas/miaoda-inspector": "^1.0.16",
|
|
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",
|
package/lib/utils/apiPath.d.ts
DELETED