@lark-apaas/client-toolkit 1.2.10-alpha.4 → 1.2.10-alpha.41
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/hooks/useScrollReveal.d.ts +1 -0
- package/lib/apis/hooks/useScrollReveal.js +1 -0
- package/lib/apis/utils/scopedStorage.d.ts +1 -0
- package/lib/apis/utils/scopedStorage.js +2 -0
- package/lib/components/AppContainer/api-proxy/core.js +2 -1
- package/lib/components/AppContainer/index.d.ts +5 -1
- package/lib/components/AppContainer/index.js +14 -27
- package/lib/components/AppContainer/safety.js +5 -2
- package/lib/components/AppContainer/utils/childApi.js +1 -0
- package/lib/components/AppContainer/utils/getLarkUser.js +4 -2
- package/lib/components/AppContainer/utils/observable.js +7 -1
- package/lib/components/AppContainer/utils/tea.js +1 -1
- package/lib/components/ErrorRender/index.js +5 -11
- package/lib/components/User/UserSelect.js +1 -13
- package/lib/components/theme/index.d.ts +0 -1
- package/lib/components/theme/index.js +0 -1
- package/lib/components/theme/util.d.ts +0 -2
- package/lib/components/theme/util.js +0 -108
- package/lib/components/ui/toast.d.ts +2 -0
- package/lib/components/ui/toast.js +53 -0
- package/lib/hooks/index.d.ts +1 -0
- package/lib/hooks/index.js +1 -0
- package/lib/hooks/useLogout.js +2 -17
- package/lib/hooks/useScrollReveal.d.ts +61 -0
- package/lib/hooks/useScrollReveal.js +37 -0
- package/lib/index.js +12 -1
- package/lib/integrations/dataloom.js +5 -3
- 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/integrations/services/types.d.ts +1 -0
- package/lib/logger/intercept-global-error.js +16 -14
- package/lib/runtime/index.d.ts +1 -0
- package/lib/runtime/index.js +1 -0
- package/lib/runtime/react-devtools-hook.d.ts +19 -0
- package/lib/runtime/react-devtools-hook.js +20 -0
- package/lib/theme-layer.css +2 -1
- package/lib/utils/apiPath.d.ts +5 -0
- package/lib/utils/apiPath.js +5 -0
- package/lib/utils/axiosConfig.js +6 -5
- package/lib/utils/getAppId.d.ts +2 -4
- package/lib/utils/getAppId.js +2 -9
- package/lib/utils/getInitialInfo.js +5 -3
- package/lib/utils/getUserProfile.js +4 -12
- package/lib/utils/hmr-api.d.ts +39 -0
- package/lib/utils/hmr-api.js +36 -0
- package/lib/utils/module-hot.d.ts +7 -2
- package/lib/utils/module-hot.js +6 -51
- package/lib/utils/requestManager.js +1 -3
- package/lib/utils/scopedStorage.d.ts +5 -0
- package/lib/utils/scopedStorage.js +46 -0
- 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/components/theme/ui-config.d.ts +0 -1
- package/lib/components/theme/ui-config.js +0 -2
- 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
|
@@ -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;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getHmrApi } from "../utils/hmr-api.js";
|
|
2
2
|
import { submitPostMessage, submitSlardarEvent } from "../utils/postMessage.js";
|
|
3
3
|
import { levelSchema } from "./log-types.js";
|
|
4
4
|
import { logger } from "./logger.js";
|
|
@@ -63,26 +63,28 @@ function processDevServerLog(log) {
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
function listenModuleHmr() {
|
|
66
|
-
const
|
|
67
|
-
if (
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
66
|
+
const hmr = getHmrApi();
|
|
67
|
+
if (hmr) {
|
|
68
|
+
hmr.onSuccess(()=>{
|
|
69
|
+
submitPostMessage({
|
|
70
|
+
type: 'DevServerMessage',
|
|
71
|
+
data: {
|
|
72
|
+
type: 'devServer-status',
|
|
73
|
+
status: 'hmr-apply-success'
|
|
74
|
+
}
|
|
75
|
+
});
|
|
74
76
|
});
|
|
75
|
-
|
|
76
|
-
console.warn('hmr apply failed',
|
|
77
|
+
hmr.onError((error)=>{
|
|
78
|
+
console.warn('hmr apply failed', error);
|
|
77
79
|
submitSlardarEvent({
|
|
78
80
|
name: 'sandbox-devServer',
|
|
79
81
|
categories: {
|
|
80
82
|
type: 'hmr-apply-failed',
|
|
81
|
-
|
|
83
|
+
error: String(error)
|
|
82
84
|
}
|
|
83
85
|
});
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
86
88
|
}
|
|
87
89
|
function interceptErrors() {
|
|
88
90
|
window.addEventListener('error', (event)=>{
|
package/lib/runtime/index.d.ts
CHANGED
package/lib/runtime/index.js
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
* When react-refresh-runtime runs first (as an rspack runtime module),
|
|
10
|
+
* it may create __REACT_DEVTOOLS_GLOBAL_HOOK__ with an inject() that
|
|
11
|
+
* doesn't populate the renderers Map. We patch the existing hook to
|
|
12
|
+
* ensure renderers are always tracked.
|
|
13
|
+
*/
|
|
14
|
+
export {};
|
|
15
|
+
declare global {
|
|
16
|
+
interface Window {
|
|
17
|
+
__REACT_DEVTOOLS_GLOBAL_HOOK__?: any;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
if ('undefined' != typeof window && 'production' !== process.env.NODE_ENV) if (window.__REACT_DEVTOOLS_GLOBAL_HOOK__) {
|
|
2
|
+
const hook = window.__REACT_DEVTOOLS_GLOBAL_HOOK__;
|
|
3
|
+
if (!(hook.renderers instanceof Map)) hook.renderers = new Map();
|
|
4
|
+
const originalInject = 'function' == typeof hook.inject ? hook.inject.bind(hook) : null;
|
|
5
|
+
hook.inject = function(renderer) {
|
|
6
|
+
const id = originalInject ? originalInject(renderer) : hook.renderers.size + 1;
|
|
7
|
+
if (null != id && !hook.renderers.has(id)) hook.renderers.set(id, renderer);
|
|
8
|
+
return id;
|
|
9
|
+
};
|
|
10
|
+
} else window.__REACT_DEVTOOLS_GLOBAL_HOOK__ = {
|
|
11
|
+
renderers: new Map(),
|
|
12
|
+
supportsFiber: true,
|
|
13
|
+
inject (renderer) {
|
|
14
|
+
const id = this.renderers.size + 1;
|
|
15
|
+
this.renderers.set(id, renderer);
|
|
16
|
+
return id;
|
|
17
|
+
},
|
|
18
|
+
onCommitFiberRoot () {},
|
|
19
|
+
onCommitFiberUnmount () {}
|
|
20
|
+
};
|
package/lib/theme-layer.css
CHANGED
package/lib/utils/axiosConfig.js
CHANGED
|
@@ -54,7 +54,7 @@ async function logResponse(ok, responseOrError) {
|
|
|
54
54
|
logTraceID
|
|
55
55
|
};
|
|
56
56
|
if (stacktrace) logMeta.stacktrace = stacktrace;
|
|
57
|
-
logger.
|
|
57
|
+
logger.log({
|
|
58
58
|
level: ok,
|
|
59
59
|
args: [
|
|
60
60
|
parts.join(''),
|
|
@@ -110,7 +110,7 @@ async function logResponse(ok, responseOrError) {
|
|
|
110
110
|
const stacktrace = await requestStacktraceMap.get(requestUUID);
|
|
111
111
|
const logMeta = {};
|
|
112
112
|
if (stacktrace) logMeta.stacktrace = stacktrace;
|
|
113
|
-
logger.
|
|
113
|
+
logger.log({
|
|
114
114
|
level: 'error',
|
|
115
115
|
args: [
|
|
116
116
|
parts.join(''),
|
|
@@ -120,7 +120,7 @@ async function logResponse(ok, responseOrError) {
|
|
|
120
120
|
});
|
|
121
121
|
return;
|
|
122
122
|
}
|
|
123
|
-
logger.
|
|
123
|
+
logger.log({
|
|
124
124
|
level: 'error',
|
|
125
125
|
args: [
|
|
126
126
|
'请求失败:无响应对象或配置信息'
|
|
@@ -234,6 +234,7 @@ function initAxiosConfig(axiosInstance) {
|
|
|
234
234
|
config._startTime = config._startTime || Date.now();
|
|
235
235
|
const csrfToken = window.csrfToken;
|
|
236
236
|
if (csrfToken) config.headers['X-Suda-Csrf-Token'] = csrfToken;
|
|
237
|
+
if ('undefined' != typeof window && window.location?.pathname) config.headers['X-Page-Route'] = window.location.pathname;
|
|
237
238
|
return config;
|
|
238
239
|
}, (error)=>Promise.reject(error));
|
|
239
240
|
instance.interceptors.response.use((response)=>response, (error)=>{
|
|
@@ -241,8 +242,8 @@ function initAxiosConfig(axiosInstance) {
|
|
|
241
242
|
if (error.response?.status === 403) {
|
|
242
243
|
const method = (error.config?.method || 'GET').toUpperCase();
|
|
243
244
|
const url = (error.config?.url || '').split('?')[0];
|
|
244
|
-
logger.
|
|
245
|
-
level: '
|
|
245
|
+
logger.log({
|
|
246
|
+
level: 'warn',
|
|
246
247
|
args: [
|
|
247
248
|
`请求被拒绝(403):${method} ${url}`,
|
|
248
249
|
{
|
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,15 +9,16 @@ 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,
|
|
16
18
|
credentials: 'include'
|
|
17
19
|
});
|
|
18
20
|
const res = await response.json();
|
|
19
|
-
if (0 === res.code) return res.data;
|
|
21
|
+
if (0 === res.code || '0' === res.status_code) return res.data;
|
|
20
22
|
console.error('Error fetching published app info:', res);
|
|
21
23
|
} catch (error) {
|
|
22
24
|
console.error('Error fetching published app info:', error);
|
|
@@ -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,
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 统一 HMR API
|
|
3
|
+
*
|
|
4
|
+
* 提供统一的 HMR 成功/失败回调接口,屏蔽 Webpack 和 Vite 的差异。
|
|
5
|
+
*
|
|
6
|
+
* - Webpack/Rspack: 通过 import.meta.webpackHot 或 module.hot
|
|
7
|
+
* - Vite: 通过 error-overlay 注入的 window.__VITE_HMR__
|
|
8
|
+
*
|
|
9
|
+
* @see docs/RFC_HMR_API.md
|
|
10
|
+
*/
|
|
11
|
+
export interface HmrApi {
|
|
12
|
+
/**
|
|
13
|
+
* 注册 HMR 成功回调
|
|
14
|
+
* @param callback 成功回调函数
|
|
15
|
+
* @returns cleanup 函数,用于取消注册
|
|
16
|
+
*/
|
|
17
|
+
onSuccess(callback: () => void): () => void;
|
|
18
|
+
/**
|
|
19
|
+
* 注册 HMR 失败回调
|
|
20
|
+
* @param callback 失败回调函数,参数为错误信息
|
|
21
|
+
* @returns cleanup 函数,用于取消注册
|
|
22
|
+
*/
|
|
23
|
+
onError(callback: (error: unknown) => void): () => void;
|
|
24
|
+
}
|
|
25
|
+
declare global {
|
|
26
|
+
interface Window {
|
|
27
|
+
__VITE_HMR__?: HmrApi;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* 获取 HMR API 实例
|
|
32
|
+
*
|
|
33
|
+
* 自动检测当前构建工具(Webpack/Vite)并返回对应实现:
|
|
34
|
+
* - Webpack/Rspack: 使用内置适配器
|
|
35
|
+
* - Vite: 使用 error-overlay 注入的 window.__VITE_HMR__
|
|
36
|
+
*
|
|
37
|
+
* @returns HmrApi 实例,如果不在开发环境或不支持 HMR 则返回 null
|
|
38
|
+
*/
|
|
39
|
+
export declare function getHmrApi(): HmrApi | null;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
function createWebpackHmrApi(hot) {
|
|
2
|
+
return {
|
|
3
|
+
onSuccess (callback) {
|
|
4
|
+
let lastStatus = null;
|
|
5
|
+
const handler = (status)=>{
|
|
6
|
+
if ('idle' === status && 'apply' === lastStatus) try {
|
|
7
|
+
callback();
|
|
8
|
+
} catch (e) {
|
|
9
|
+
console.error('[HMR] Success callback error:', e);
|
|
10
|
+
}
|
|
11
|
+
lastStatus = status;
|
|
12
|
+
};
|
|
13
|
+
hot.addStatusHandler(handler);
|
|
14
|
+
return ()=>hot.removeStatusHandler(handler);
|
|
15
|
+
},
|
|
16
|
+
onError (callback) {
|
|
17
|
+
const handler = (status)=>{
|
|
18
|
+
if ('fail' === status || 'abort' === status) try {
|
|
19
|
+
callback(new Error(`HMR ${status}`));
|
|
20
|
+
} catch (e) {
|
|
21
|
+
console.error('[HMR] Error callback error:', e);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
hot.addStatusHandler(handler);
|
|
25
|
+
return ()=>hot.removeStatusHandler(handler);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function getHmrApi() {
|
|
30
|
+
if ('production' === process.env.NODE_ENV) return null;
|
|
31
|
+
if (import.meta.webpackHot) return createWebpackHmrApi(import.meta.webpackHot);
|
|
32
|
+
'undefined' != typeof module && module.hot;
|
|
33
|
+
if (window.__VITE_HMR__) return window.__VITE_HMR__;
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
export { getHmrApi };
|
|
@@ -15,10 +15,15 @@ export interface ModuleHotInstance {
|
|
|
15
15
|
addStatusHandler: (handler: (status: ModuleHotType) => void) => void;
|
|
16
16
|
removeStatusHandler: (handler: (status: ModuleHotType) => void) => void;
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* 获取 Webpack HMR 实例
|
|
20
|
+
* 仅支持 Webpack/Rspack 的 HMR API
|
|
21
|
+
*/
|
|
18
22
|
export declare function getModuleHot(): ModuleHotInstance | null;
|
|
19
23
|
/**
|
|
20
24
|
* 创建模块热更成功处理函数
|
|
21
|
-
*
|
|
22
|
-
*
|
|
25
|
+
* 监听模块热更状态,检测 apply -> idle 转换表示热更成功
|
|
26
|
+
*
|
|
27
|
+
* @param callback 热更回调函数,参数为是否成功和当前状态
|
|
23
28
|
*/
|
|
24
29
|
export declare function createApplyHandle(callback: (success: boolean, status: ModuleHotType) => void): (status: ModuleHotType) => void;
|
package/lib/utils/module-hot.js
CHANGED
|
@@ -1,66 +1,21 @@
|
|
|
1
|
-
function createViteHmrAdapter(viteHot) {
|
|
2
|
-
const handlers = new Set();
|
|
3
|
-
const notifyHandlers = (status)=>{
|
|
4
|
-
handlers.forEach((handler)=>{
|
|
5
|
-
try {
|
|
6
|
-
handler(status);
|
|
7
|
-
} catch (e) {
|
|
8
|
-
console.error('[HMR] Status handler error:', e);
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
};
|
|
12
|
-
const beforeUpdateHandler = ()=>{
|
|
13
|
-
notifyHandlers('prepare');
|
|
14
|
-
setTimeout(()=>notifyHandlers('apply'), 0);
|
|
15
|
-
};
|
|
16
|
-
const afterUpdateHandler = ()=>{
|
|
17
|
-
notifyHandlers('idle');
|
|
18
|
-
};
|
|
19
|
-
const errorHandler = ()=>{
|
|
20
|
-
notifyHandlers('fail');
|
|
21
|
-
};
|
|
22
|
-
const beforeFullReloadHandler = ()=>{
|
|
23
|
-
notifyHandlers('check');
|
|
24
|
-
};
|
|
25
|
-
viteHot.on('vite:beforeUpdate', beforeUpdateHandler);
|
|
26
|
-
viteHot.on('vite:afterUpdate', afterUpdateHandler);
|
|
27
|
-
viteHot.on('vite:error', errorHandler);
|
|
28
|
-
viteHot.on('vite:beforeFullReload', beforeFullReloadHandler);
|
|
29
|
-
return {
|
|
30
|
-
addStatusHandler (handler) {
|
|
31
|
-
handlers.add(handler);
|
|
32
|
-
},
|
|
33
|
-
removeStatusHandler (handler) {
|
|
34
|
-
handlers.delete(handler);
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
let viteAdapterInstance = null;
|
|
39
1
|
function getModuleHot() {
|
|
40
2
|
if ('production' === process.env.NODE_ENV) return null;
|
|
41
|
-
if (import.meta.hot) {
|
|
42
|
-
if (!viteAdapterInstance) viteAdapterInstance = createViteHmrAdapter(import.meta.hot);
|
|
43
|
-
return viteAdapterInstance;
|
|
44
|
-
}
|
|
45
3
|
if (import.meta.webpackHot) return import.meta.webpackHot;
|
|
46
4
|
'undefined' != typeof module && module.hot;
|
|
47
5
|
return null;
|
|
48
6
|
}
|
|
49
7
|
function createApplyHandle(callback) {
|
|
50
|
-
let
|
|
8
|
+
let lastStatus = null;
|
|
51
9
|
return (status)=>{
|
|
52
10
|
if ('fail' === status || 'abort' === status) {
|
|
53
|
-
|
|
11
|
+
lastStatus = status;
|
|
54
12
|
return callback(false, status);
|
|
55
13
|
}
|
|
56
|
-
if (
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
callback(true, status);
|
|
60
|
-
}
|
|
61
|
-
return;
|
|
14
|
+
if ('idle' === status && 'apply' === lastStatus) {
|
|
15
|
+
lastStatus = status;
|
|
16
|
+
return callback(true, status);
|
|
62
17
|
}
|
|
63
|
-
|
|
18
|
+
lastStatus = status;
|
|
64
19
|
};
|
|
65
20
|
}
|
|
66
21
|
export { createApplyHandle, getModuleHot };
|
|
@@ -4,9 +4,7 @@ async function fetchUserProfilesByIds(ids) {
|
|
|
4
4
|
try {
|
|
5
5
|
const dataloom = await getDataloom();
|
|
6
6
|
if (!dataloom) throw new Error('Dataloom client is unavailable');
|
|
7
|
-
const
|
|
8
|
-
if (0 === numericIds.length) return [];
|
|
9
|
-
const response = await dataloom.service.user.getByIds(numericIds);
|
|
7
|
+
const response = await dataloom.service.user.getByIds(ids);
|
|
10
8
|
return Array.isArray(response?.data) ? response.data : response?.data?.user_list || [];
|
|
11
9
|
} catch (error) {
|
|
12
10
|
console.error(`Failed to fetch profiles for user IDs ${ids.join(', ')}:`, error);
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { getAppId } from "./getAppId.js";
|
|
2
|
+
function getPrefix() {
|
|
3
|
+
const appId = getAppId();
|
|
4
|
+
const namespace = appId || '__global__';
|
|
5
|
+
return `__miaoda_${namespace}__:`;
|
|
6
|
+
}
|
|
7
|
+
function getScopedKeys() {
|
|
8
|
+
const prefix = getPrefix();
|
|
9
|
+
const keys = [];
|
|
10
|
+
for(let i = 0; i < localStorage.length; i++){
|
|
11
|
+
const key = localStorage.key(i);
|
|
12
|
+
if (key && key.startsWith(prefix)) keys.push(key.substring(prefix.length));
|
|
13
|
+
}
|
|
14
|
+
return keys;
|
|
15
|
+
}
|
|
16
|
+
const scopedStorage = {
|
|
17
|
+
getItem (key) {
|
|
18
|
+
const prefixedKey = getPrefix() + key;
|
|
19
|
+
return localStorage.getItem(prefixedKey);
|
|
20
|
+
},
|
|
21
|
+
setItem (key, value) {
|
|
22
|
+
const prefixedKey = getPrefix() + key;
|
|
23
|
+
localStorage.setItem(prefixedKey, value);
|
|
24
|
+
},
|
|
25
|
+
removeItem (key) {
|
|
26
|
+
const prefixedKey = getPrefix() + key;
|
|
27
|
+
localStorage.removeItem(prefixedKey);
|
|
28
|
+
},
|
|
29
|
+
clear () {
|
|
30
|
+
const prefix = getPrefix();
|
|
31
|
+
const keysToRemove = [];
|
|
32
|
+
for(let i = 0; i < localStorage.length; i++){
|
|
33
|
+
const key = localStorage.key(i);
|
|
34
|
+
if (key && key.startsWith(prefix)) keysToRemove.push(key);
|
|
35
|
+
}
|
|
36
|
+
keysToRemove.forEach((key)=>localStorage.removeItem(key));
|
|
37
|
+
},
|
|
38
|
+
key (index) {
|
|
39
|
+
const keys = getScopedKeys();
|
|
40
|
+
return keys[index] || null;
|
|
41
|
+
},
|
|
42
|
+
get length () {
|
|
43
|
+
return getScopedKeys().length;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
export { scopedStorage };
|
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.41",
|
|
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.9-alpha.2",
|
|
97
|
+
"@lark-apaas/auth-sdk": "0.1.0-alpha.56",
|
|
98
|
+
"@lark-apaas/client-capability": "0.1.3-alpha.15",
|
|
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 { defaultUIConfig, type UIComponentConfig, } from '@lark-apaas/miaoda-inspector';
|
|
@@ -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 };
|