@lark-apaas/miaoda-core 0.1.0-alpha.13 → 0.1.0-alpha.14

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.
Files changed (36) hide show
  1. package/lib/apis/hooks/useAppInfo.d.ts +1 -0
  2. package/lib/apis/hooks/useAppInfo.js +1 -0
  3. package/lib/components/AppContainer/index.js +1 -1
  4. package/lib/components/TopNav/TitleBar.js +5 -2
  5. package/lib/components/TopNav/TopNav.js +2 -2
  6. package/lib/components/User/UserDisplay.d.ts +1 -1
  7. package/lib/components/common/LogoInfo.js +2 -2
  8. package/lib/components/theme/ThemeProvider.d.ts +2 -2
  9. package/lib/components/theme/ThemeProvider.js +3 -3
  10. package/lib/components/theme/constants.d.ts +1 -1
  11. package/lib/components/theme/constants.js +2 -1
  12. package/lib/components/theme/ui-config.d.ts +1 -49
  13. package/lib/components/theme/ui-config.js +1 -757
  14. package/lib/components/theme/util.d.ts +3 -3
  15. package/lib/components/theme/util.js +2 -2
  16. package/lib/hooks/index.d.ts +1 -1
  17. package/lib/hooks/index.js +1 -1
  18. package/lib/hooks/{useCurrentAppInfo.d.ts → useAppInfo.d.ts} +1 -1
  19. package/lib/hooks/{useCurrentAppInfo.js → useAppInfo.js} +2 -2
  20. package/lib/hooks/useCurrentUserProfile.js +31 -2
  21. package/lib/hooks/useLogout.js +12 -0
  22. package/lib/index.css +1 -0
  23. package/lib/inspector.dev.css +10 -0
  24. package/lib/integrations/dataloom.js +11 -2
  25. package/lib/integrations/generateImage.js +14 -0
  26. package/lib/integrations/generateTextStream.js +23 -9
  27. package/lib/tailwind-theme.css +1 -101
  28. package/lib/theme-layer.css +3 -0
  29. package/lib/utils/getAppId.d.ts +1 -1
  30. package/lib/utils/getAppId.js +4 -2
  31. package/lib/utils/getCsrfToken.d.ts +5 -0
  32. package/lib/utils/getCsrfToken.js +10 -0
  33. package/lib/utils/getUserProfile.js +6 -1
  34. package/package.json +3 -3
  35. package/lib/apis/hooks/useCurrentAppInfo.d.ts +0 -1
  36. package/lib/apis/hooks/useCurrentAppInfo.js +0 -1
@@ -1,7 +1,7 @@
1
1
  import { type ThemeConfig } from 'antd';
2
2
  import { UIComponentConfig } from './ui-config';
3
3
  export type IThemeMode = 'dark' | 'light' | 'system';
4
- export interface IThemeMeta {
4
+ export interface IThemeTokenMeta {
5
5
  /**
6
6
  * 品牌色
7
7
  */
@@ -16,5 +16,5 @@ export interface IThemeMeta {
16
16
  spacing: number;
17
17
  }
18
18
  export declare const generateTailwindRadiusToken: (radiusRemValue: number) => UIComponentConfig;
19
- export declare function generateLightTheme(override?: Partial<IThemeMeta>): ThemeConfig;
20
- export declare function generateDarkTheme(override?: Partial<IThemeMeta>): ThemeConfig;
19
+ export declare function generateLightTheme(override?: Partial<IThemeTokenMeta>): ThemeConfig;
20
+ export declare function generateDarkTheme(override?: Partial<IThemeTokenMeta>): ThemeConfig;
@@ -169,7 +169,7 @@ function generateLightTheme(override) {
169
169
  token: {
170
170
  ...defaultLightTheme.token,
171
171
  ...generateColorPrimaryToken(override?.colorPrimary || lightColorPrimary, 'light'),
172
- ...generateBorderRadiusTokenSyncTailwind(override?.borderRadius || 4),
172
+ ...generateBorderRadiusTokenSyncTailwind(override?.borderRadius),
173
173
  ...generateSpacingToken(override)
174
174
  }
175
175
  };
@@ -180,7 +180,7 @@ function generateDarkTheme(override) {
180
180
  token: {
181
181
  ...defaultDarkTheme.token,
182
182
  ...generateColorPrimaryToken(override?.colorPrimary || darkColorPrimary, 'dark'),
183
- ...generateBorderRadiusTokenSyncTailwind(override?.borderRadius || 4),
183
+ ...generateBorderRadiusTokenSyncTailwind(override?.borderRadius),
184
184
  ...generateSpacingToken(override)
185
185
  }
186
186
  };
@@ -1,4 +1,4 @@
1
- export * from './useCurrentAppInfo';
1
+ export * from './useAppInfo';
2
2
  export * from './useCurrentUserProfile';
3
3
  export * from './useIsMobile';
4
4
  export * from './useLogout';
@@ -1,4 +1,4 @@
1
- export * from "./useCurrentAppInfo.js";
1
+ export * from "./useAppInfo.js";
2
2
  export * from "./useCurrentUserProfile.js";
3
3
  export * from "./useIsMobile.js";
4
4
  export * from "./useLogout.js";
@@ -1,4 +1,4 @@
1
- export declare const useCurrentAppInfo: () => {
1
+ export declare const useAppInfo: () => {
2
2
  appName: string;
3
3
  appLogo: string;
4
4
  name?: string;
@@ -1,6 +1,6 @@
1
1
  import { useEffect, useState } from "react";
2
2
  import { getAppInfo } from "../integrations/getAppInfo.js";
3
- const useCurrentAppInfo = ()=>{
3
+ const useAppInfo = ()=>{
4
4
  const [appInfo, setAppInfo] = useState(()=>getAppInfo());
5
5
  useEffect(()=>{
6
6
  const handleMetaInfoChanged = ()=>{
@@ -17,4 +17,4 @@ const useCurrentAppInfo = ()=>{
17
17
  appLogo: appInfo.avatar
18
18
  };
19
19
  };
20
- export { useCurrentAppInfo };
20
+ export { useAppInfo };
@@ -1,6 +1,7 @@
1
1
  import { useEffect, useState } from "react";
2
2
  import { logger } from "../logger/index.js";
3
3
  import { getCurrentUserProfile } from "../integrations/getCurrentUserProfile.js";
4
+ import { dataloom } from "../integrations/dataloom.js";
4
5
  function getCompatibilityUserProfile() {
5
6
  const userInfo = getCurrentUserProfile();
6
7
  return {
@@ -12,8 +13,36 @@ function getCompatibilityUserProfile() {
12
13
  const useCurrentUserProfile = ()=>{
13
14
  const [userInfo, setUserInfo] = useState(()=>getCompatibilityUserProfile());
14
15
  useEffect(()=>{
15
- const handleMetaInfoChanged = ()=>{
16
- logger.info('MiaoDaMetaInfoChanged', getCurrentUserProfile());
16
+ let handleMetaInfoChanged;
17
+ if (window._IS_Spark_RUNTIME) {
18
+ (async ()=>{
19
+ const result = await dataloom.service.session.getUserInfo();
20
+ const userInfo = result?.data?.user_info;
21
+ setUserInfo({
22
+ user_id: userInfo.user_id?.toString(),
23
+ email: userInfo.email,
24
+ name: userInfo.name?.[0]?.text,
25
+ avatar: userInfo.avatar?.image?.large,
26
+ userName: userInfo?.name?.[0]?.text,
27
+ userAvatar: userInfo?.avatar?.image?.large
28
+ });
29
+ })();
30
+ handleMetaInfoChanged = async ()=>{
31
+ const result = await dataloom.service.session.getUserInfo();
32
+ const userInfo = result?.data?.user_info;
33
+ const newUserInfo = {
34
+ user_id: userInfo.user_id?.toString(),
35
+ email: userInfo.email,
36
+ name: userInfo.name?.[0]?.text,
37
+ avatar: userInfo.avatar?.image?.large,
38
+ userName: userInfo?.name?.[0]?.text,
39
+ userAvatar: userInfo?.avatar?.image?.large
40
+ };
41
+ logger.info('MiaoDaMetaInfoChanged', newUserInfo);
42
+ setUserInfo(newUserInfo);
43
+ };
44
+ } else handleMetaInfoChanged = ()=>{
45
+ logger.info('MiaoDaMetaInfoChanged', getCompatibilityUserProfile());
17
46
  setUserInfo(getCompatibilityUserProfile());
18
47
  };
19
48
  window.addEventListener('MiaoDaMetaInfoChanged', handleMetaInfoChanged);
@@ -1,8 +1,20 @@
1
1
  import { useState } from "react";
2
+ import { dataloom } from "../integrations/dataloom.js";
2
3
  function useLogout() {
3
4
  const [isLoading, setIsLoading] = useState(false);
4
5
  async function handlerLogout() {
5
6
  if ('production' !== process.env.NODE_ENV) return void console.log('只有生产环境才执行登出');
7
+ if (window._IS_Spark_RUNTIME) {
8
+ setIsLoading(true);
9
+ try {
10
+ await dataloom.service.session.signOut();
11
+ } catch (error) {
12
+ console.error('登出失败', error);
13
+ } finally{
14
+ setIsLoading(false);
15
+ }
16
+ return;
17
+ }
6
18
  setIsLoading(true);
7
19
  try {
8
20
  await fetch('/ai/api/ui/page/logout', {
package/lib/index.css CHANGED
@@ -1,3 +1,4 @@
1
+ @import "./theme-layer.css";
1
2
  @import "./tailwind-theme.css";
2
3
  @import "./override.css";
3
4
 
@@ -0,0 +1,10 @@
1
+ @source inline("text-{xs,sm,base,lg,xl,2xl,3xl,4xl,5xl,6xl,7xl,8xl,9xl}");
2
+
3
+ @source inline("{bg,text,border}-{blue,pink,neutral,red,orange,violet,lime,yellow,green,teal,cyan,indigo,purple,amber,emerald,slate}-{50,{100..900..100},950}");
4
+
5
+ @source inline("{bg,text,border}-{blue,pink,neutral,red,orange,violet,lime,yellow,green,teal,cyan,indigo,purple,amber,emerald,slate}");
6
+
7
+ @source inline("{bg,text,border}-neutral-{00,1000}");
8
+
9
+ @source inline("rounded-{none,sm,md,lg,xl,full}");
10
+
@@ -1,16 +1,25 @@
1
1
  import { splitWorkspaceUrl } from "../utils/url.js";
2
2
  import { createClient } from "@data-loom/js";
3
+ import { getAppId } from "../utils/getAppId.js";
3
4
  const PAT_URL_NAMESPACE = 'FEISUDA_UUU';
4
5
  const PAT_TOKEN_NAMESPACE = 'FEISUDA_TTT';
5
6
  const DATALOOM_CLIENT_URL = window[PAT_URL_NAMESPACE];
6
7
  const DATALOOM_PAT = window[PAT_TOKEN_NAMESPACE];
7
8
  const createDataLoomClient = (url, pat)=>{
8
- if (!url || !pat) return null;
9
+ if (!url) return null;
9
10
  const { baseUrl, workspace } = splitWorkspaceUrl(url);
11
+ const appId = getAppId(window.location.pathname);
10
12
  return createClient(baseUrl, pat, workspace, {
11
13
  global: {
12
14
  enablePostgresBuilderLog: 'production' !== process.env.NODE_ENV,
13
- requestRateLimit: 'production' !== process.env.NODE_ENV ? 100 : void 0
15
+ requestRateLimit: 'production' !== process.env.NODE_ENV ? 100 : void 0,
16
+ brandName: 'miaoda',
17
+ appId,
18
+ onError: (error, dataloomInstance)=>{
19
+ if (error?.status === 401) {
20
+ if (error?.code === 'k_ident_013001') dataloomInstance.service.session.redirectToLogin();
21
+ }
22
+ }
14
23
  }
15
24
  });
16
25
  };
@@ -1,4 +1,5 @@
1
1
  import { getAppId } from "../utils/getAppId.js";
2
+ import { getCsrfToken } from "../utils/getCsrfToken.js";
2
3
  import { getEnvPath } from "../utils/getEnvPath.js";
3
4
  async function generateImage(prompt, size = '1024x1024', headers = {}) {
4
5
  const appId = getAppId(window.location.pathname);
@@ -18,6 +19,19 @@ async function generateImage(prompt, size = '1024x1024', headers = {}) {
18
19
  'x-lgw-csrf-token': window.lgw_csrf_token,
19
20
  ...window.CSRF_HEADERS || {}
20
21
  };
22
+ if (window._IS_Spark_RUNTIME) {
23
+ mergedHeaders['X-Suda-Csrf-Token'] = getCsrfToken();
24
+ const response = await fetch(`${window.location.origin}/spark/b/${appId}/text2image`, {
25
+ method: 'POST',
26
+ headers: mergedHeaders,
27
+ credentials: 'include',
28
+ body: JSON.stringify({
29
+ prompt: prompt,
30
+ size: size
31
+ })
32
+ });
33
+ return await response.json();
34
+ }
21
35
  const response = await fetch(`${window.location.origin}/ai/api/${getEnvPath()}/v1/apps/${appId}/text2image`, {
22
36
  method: 'POST',
23
37
  headers: mergedHeaders,
@@ -1,4 +1,5 @@
1
1
  import { getAppId } from "../utils/getAppId.js";
2
+ import { getCsrfToken } from "../utils/getCsrfToken.js";
2
3
  import { getEnvPath } from "../utils/getEnvPath.js";
3
4
  async function generateTextStream(options, onChunk) {
4
5
  const { text, thinking_type = 'disabled', headers = {} } = options;
@@ -10,16 +11,29 @@ async function generateTextStream(options, onChunk) {
10
11
  error: 'appId is required'
11
12
  };
12
13
  try {
13
- const response = await fetch(`${window.location.origin}/ai/api/${getEnvPath()}/v1/apps/${appId}/text/generate`, {
14
+ const mergedHeaders = {
15
+ 'Content-Type': 'application/json',
16
+ ...headers,
17
+ 'X-Kunlun-Token': window.token,
18
+ 'x-miaoda-token': window.MIAODA_BUILTIN_TTT,
19
+ 'x-lgw-csrf-token': window.lgw_csrf_token,
20
+ ...window.CSRF_HEADERS || {}
21
+ };
22
+ let response;
23
+ if (window._IS_Spark_RUNTIME) {
24
+ mergedHeaders['X-Suda-Csrf-Token'] = getCsrfToken();
25
+ response = await fetch(`${window.location.origin}/spark/b/${appId}/text/generate`, {
26
+ method: 'POST',
27
+ headers: mergedHeaders,
28
+ credentials: 'include',
29
+ body: JSON.stringify({
30
+ text,
31
+ thinking_type
32
+ })
33
+ });
34
+ } else response = await fetch(`${window.location.origin}/ai/api/${getEnvPath()}/v1/apps/${appId}/text/generate`, {
14
35
  method: 'POST',
15
- headers: {
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
- },
36
+ headers: mergedHeaders,
23
37
  credentials: 'include',
24
38
  body: JSON.stringify({
25
39
  text,
@@ -1,39 +1,7 @@
1
- @import "tailwindcss";
2
- @layer theme;
1
+ @import "@/inspector.dev.css";
3
2
 
4
3
  @layer base {
5
4
  :root {
6
- --color-background: #fff;
7
- --color-foreground: #1f2329;
8
- --color-card: #fff;
9
- --color-card-foreground: #1f2329;
10
- --color-popover: #fff;
11
- --color-popover-foreground: #1f2329;
12
- --color-primary: #1456f0;
13
- --color-primary-foreground: #f8f9fa;
14
- --color-secondary: #f2f3f5;
15
- --color-secondary-foreground: #1f2329;
16
- --color-muted: #f2f3f5;
17
- --color-muted-foreground: #8f959e;
18
- --color-accent: #f2f3f5;
19
- --color-accent-foreground: #1f2329;
20
- --color-destructive: #f54a45;
21
- --color-border: #dee0e3;
22
- --color-input: #dee0e3;
23
- --color-ring: #d0d3d6;
24
- --color-chart-1: #3370eb;
25
- --color-chart-2: #1bcebf;
26
- --color-chart-3: #ffc60a;
27
- --color-chart-4: #ed6d0c;
28
- --color-chart-5: #dca1e4;
29
- --color-sidebar: #fafafa;
30
- --color-sidebar-foreground: #1f2329;
31
- --color-sidebar-primary: #373c43;
32
- --color-sidebar-primary-foreground: #f8f9fa;
33
- --color-sidebar-accent: #f2f3f5;
34
- --color-sidebar-accent-foreground: #1f2329;
35
- --color-sidebar-border: #dee0e3;
36
- --color-sidebar-ring: #d0d3d6;
37
5
  --color-blue-50: #f0f4ff;
38
6
  --color-blue-100: #e0e9ff;
39
7
  --color-blue-200: #c2d4ff;
@@ -197,53 +165,9 @@
197
165
  --bgTextSelection: 20, 86, 240, .3;
198
166
  --lineDividerDefault: 31, 35, 41, .15;
199
167
  --lineDividerModule: 31, 35, 41, .15;
200
- --font-sans: "Geist", "Geist Fallback", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
201
- --font-serif: "Geist", "Geist Fallback", ui-serif, Georgia, Cambria, "Times New Roman", Times, serif;
202
- --font-mono: Source Code Pro, monospace;
203
- --radius: .5rem;
204
- --shadow-2xs: 0px 6px 12px 0px #1f232903;
205
- --shadow-xs: 0px 6px 12px 0px #1f232903;
206
- --shadow-sm: 0px 6px 12px 0px #1f232908, 0px 1px 2px -1px #1f232908;
207
- --shadow: 0px 6px 12px 0px #1f232908, 0px 1px 2px -1px #1f232908;
208
- --shadow-md: 0px 6px 12px 0px #1f232908, 0px 2px 4px -1px #1f232908;
209
- --shadow-lg: 0px 6px 12px 0px #1f232908, 0px 4px 6px -1px #1f232908;
210
- --shadow-xl: 0px 6px 12px 0px #1f232908, 0px 8px 10px -1px #1f232908;
211
- --shadow-2xl: 0px 6px 12px 0px #1f232912;
212
- --spacing: .3rem;
213
168
  }
214
169
 
215
170
  .dark {
216
- --color-background: #0a0a0a;
217
- --color-foreground: #ebebeb;
218
- --color-card: #1a1a1a;
219
- --color-card-foreground: #ebebeb;
220
- --color-popover: #1a1a1a;
221
- --color-popover-foreground: #ebebeb;
222
- --color-primary: #336df4;
223
- --color-primary-foreground: #ebebeb;
224
- --color-secondary: #27272a;
225
- --color-secondary-foreground: #fafafa;
226
- --color-muted: #1a1a1a;
227
- --color-muted-foreground: #9f9fa9;
228
- --color-accent: #373737;
229
- --color-accent-foreground: #fafafa;
230
- --color-destructive: #f05b56;
231
- --color-border: #ebebeb26;
232
- --color-input: #ebebeb26;
233
- --color-ring: #505050;
234
- --color-chart-1: #336df4;
235
- --color-chart-2: #00bc7d;
236
- --color-chart-3: #fe9a00;
237
- --color-chart-4: #ad46ff;
238
- --color-chart-5: #ff2056;
239
- --color-sidebar: #18181b;
240
- --color-sidebar-foreground: #ebebeb;
241
- --color-sidebar-primary: #336df4;
242
- --color-sidebar-primary-foreground: #fafafa;
243
- --color-sidebar-accent: #27272a;
244
- --color-sidebar-accent-foreground: #fafafa;
245
- --color-sidebar-border: #ffffff1a;
246
- --color-sidebar-ring: #71717b;
247
171
  --color-blue-50: #152340;
248
172
  --color-blue-100: #173166;
249
173
  --color-blue-200: #194294;
@@ -406,30 +330,6 @@
406
330
  --bgTextSelection: 117, 164, 255, .3;
407
331
  --lineDividerDefault: 207, 207, 207, .15;
408
332
  --lineDividerModule: 0, 0, 0, 1;
409
- --shadow-2xs: 0 1px 3px 0px #0000000d;
410
- --shadow-xs: 0 1px 3px 0px #0000000d;
411
- --shadow-sm: 0 1px 3px 0px #0000001a, 0 1px 2px -1px #0000001a;
412
- --shadow: 0 1px 3px 0px #0000001a, 0 1px 2px -1px #0000001a;
413
- --shadow-md: 0 1px 3px 0px #0000001a, 0 2px 4px -1px #0000001a;
414
- --shadow-lg: 0 1px 3px 0px #0000001a, 0 4px 6px -1px #0000001a;
415
- --shadow-xl: 0 1px 3px 0px #0000001a, 0 8px 10px -1px #0000001a;
416
- --shadow-2xl: 0 1px 3px 0px #00000040;
417
333
  }
418
334
  }
419
335
 
420
- @layer components, utilities;
421
-
422
- @source inline("text-{xs,sm,base,lg,xl,2xl,3xl,4xl,5xl,6xl,7xl,8xl,9xl}");
423
-
424
- @source inline("{bg,text,border}-{blue,pink,neutral,red,orange,violet,lime,yellow,green,teal,cyan,indigo,purple,amber,emerald,slate}-{50,{100..900..100},950}");
425
-
426
- @source inline("{bg,text,border}-{blue,pink,neutral,red,orange,violet,lime,yellow,green,teal,cyan,indigo,purple,amber,emerald,slate}");
427
-
428
- @source inline("{bg,text,border}-neutral-{00,1000}");
429
-
430
- @source inline("rounded-{none,sm,md,lg,xl,full}");
431
-
432
- @theme {
433
- --color-background: var(--color-background) ; --color-foreground: var(--color-foreground) ; --color-card: var(--color-card) ; --color-card-foreground: var(--color-card-foreground) ; --color-popover: var(--color-popover) ; --color-popover-foreground: var(--color-popover-foreground) ; --color-primary: var(--color-primary) ; --color-primary-foreground: var(--color-primary-foreground) ; --color-secondary: var(--color-secondary) ; --color-secondary-foreground: var(--color-secondary-foreground) ; --color-muted: var(--color-muted) ; --color-muted-foreground: var(--color-muted-foreground) ; --color-accent: var(--color-accent) ; --color-accent-foreground: var(--color-accent-foreground) ; --color-destructive: var(--color-destructive) ; --color-border: var(--color-border) ; --color-input: var(--color-input) ; --color-ring: var(--color-ring) ; --color-chart-1: var(--color-chart-1) ; --color-chart-2: var(--color-chart-2) ; --color-chart-3: var(--color-chart-3) ; --color-chart-4: var(--color-chart-4) ; --color-chart-5: var(--color-chart-5) ; --color-sidebar: var(--color-sidebar) ; --color-sidebar-foreground: var(--color-sidebar-foreground) ; --color-sidebar-primary: var(--color-sidebar-primary) ; --color-sidebar-primary-foreground: var(--color-sidebar-primary-foreground) ; --color-sidebar-accent: var(--color-sidebar-accent) ; --color-sidebar-accent-foreground: var(--color-sidebar-accent-foreground) ; --color-sidebar-border: var(--color-sidebar-border) ; --color-sidebar-ring: var(--color-sidebar-ring) ; --color-crm-blue: #3b82f6; --color-crm-lightBlue: #93c5fd; --color-crm-darkBlue: #1e40af; --color-crm-gray: #6b7280; --color-crm-lightGray: #e5e7eb; --color-crm-darkGray: #374151; --font-sans: var(--font-sans) ; --font-mono: var(--font-mono) ; --font-serif: var(--font-serif) ; --radius-sm: calc(var(--radius) - 4px) ; --radius: var(--radius) ; --radius-md: calc(var(--radius) - 2px) ; --radius-lg: var(--radius) ; --radius-xl: calc(var(--radius) + 4px) ; --shadow-2xs: var(--shadow-2xs) ; --shadow-xs: var(--shadow-xs) ; --shadow-sm: var(--shadow-sm) ; --shadow: var(--shadow) ; --shadow-md: var(--shadow-md) ; --shadow-lg: var(--shadow-lg) ; --shadow-xl: var(--shadow-xl) ; --shadow-2xl: var(--shadow-2xl) ;
434
- }
435
-
@@ -0,0 +1,3 @@
1
+ @layer theme, base, antd, components, utilities;
2
+ @import "tailwindcss";
3
+
@@ -8,4 +8,4 @@ declare global {
8
8
  * @param {string} path - 输入路径字符串
9
9
  * @returns {string|null} - 提取的目录名或null
10
10
  */
11
- export declare function getAppId(path: string): string;
11
+ export declare function getAppId(path: string): string | null;
@@ -1,9 +1,11 @@
1
1
  function getAppId(path) {
2
2
  if (window.MIAODA_APP_ID) return window.MIAODA_APP_ID;
3
- const prefix = location.pathname.includes('/ai/feida/runtime/') ? '/ai/feida/runtime/' : '/ai/miaoda/';
3
+ let prefix;
4
+ prefix = path.includes('/ai/feida/runtime/') ? '/ai/feida/runtime/' : path.includes('/spark/r/') ? '/spark/r/' : '/ai/miaoda/';
4
5
  if (!path.startsWith(prefix)) return null;
5
6
  const remainder = path.substring(prefix.length);
6
7
  const nextSlashIndex = remainder.indexOf('/');
7
- return -1 === nextSlashIndex ? remainder : remainder.substring(0, nextSlashIndex);
8
+ if (-1 === nextSlashIndex) return remainder;
9
+ return remainder.substring(0, nextSlashIndex);
8
10
  }
9
11
  export { getAppId };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 获取cookie中存放的suda-csrf-token值
3
+ * @returns {string | null} - suda-csrf-token的值,如果不存在则返回null
4
+ */
5
+ export declare function getCsrfToken(): string;
@@ -0,0 +1,10 @@
1
+ function getCsrfToken() {
2
+ const cookieName = 'suda-csrf-token';
3
+ const cookies = document.cookie.split('; ');
4
+ for (const cookie of cookies){
5
+ const [name, value] = cookie.split('=');
6
+ if (name === cookieName) return decodeURIComponent(value);
7
+ }
8
+ return null;
9
+ }
10
+ export { getCsrfToken };
@@ -1,4 +1,5 @@
1
1
  import { getAppId } from "./getAppId.js";
2
+ import { getCsrfToken } from "./getCsrfToken.js";
2
3
  import { getEnvPath } from "./getEnvPath.js";
3
4
  async function getUserProfile(request, headers = {}) {
4
5
  const appId = getAppId(window.location.pathname);
@@ -19,7 +20,11 @@ async function getUserProfile(request, headers = {}) {
19
20
  ...window.CSRF_HEADERS || {}
20
21
  };
21
22
  const envPath = getEnvPath();
22
- const endpoint = `/ai/api/${envPath}/v1/apps/${appId}/user/profile`;
23
+ let endpoint;
24
+ if (window._IS_Spark_RUNTIME) {
25
+ endpoint = `/spark/b/${appId}/user/profile`;
26
+ mergedHeaders['X-Suda-Csrf-Token'] = getCsrfToken();
27
+ } else endpoint = `/ai/api/${envPath}/v1/apps/${appId}/user/profile`;
23
28
  const response = await fetch(`${window.location.origin}${endpoint}`, {
24
29
  method: 'POST',
25
30
  headers: mergedHeaders,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/miaoda-core",
3
- "version": "0.1.0-alpha.13",
3
+ "version": "0.1.0-alpha.14",
4
4
  "types": "./lib/index.d.ts",
5
5
  "main": "./lib/index.js",
6
6
  "files": [
@@ -60,7 +60,7 @@
60
60
  "dependencies": {
61
61
  "@ant-design/colors": "^7.2.1",
62
62
  "@ant-design/cssinjs": "^1.24.0",
63
- "@data-loom/js": "0.2.3",
63
+ "@data-loom/js": "0.3.1",
64
64
  "clsx": "~2.0.1",
65
65
  "dayjs": "^1.11.13",
66
66
  "echarts": "^6.0.0",
@@ -70,7 +70,7 @@
70
70
  "tailwind-merge": "~2.0.0",
71
71
  "tailwind-variants": "0.3.1",
72
72
  "tailwindcss-animate": "^1.0.7",
73
- "@lark-apaas/miaoda-inspector": "0.1.0-alpha.5"
73
+ "@lark-apaas/miaoda-inspector": "0.1.0-alpha.6"
74
74
  },
75
75
  "devDependencies": {
76
76
  "@biomejs/biome": "2.0.6",
@@ -1 +0,0 @@
1
- export * from '../../hooks/useCurrentAppInfo';
@@ -1 +0,0 @@
1
- export * from "../../hooks/useCurrentAppInfo.js";