@alauda/doom 1.11.0 → 1.12.1

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 (83) hide show
  1. package/assets/alert.svg +1 -0
  2. package/assets/angle-down.svg +1 -0
  3. package/assets/assistant.svg +1 -0
  4. package/assets/close.svg +1 -0
  5. package/assets/logout.svg +1 -0
  6. package/assets/new-chat.svg +1 -0
  7. package/assets/question-circle.svg +1 -0
  8. package/assets/send.svg +1 -0
  9. package/lib/cli/load-config.js +4 -0
  10. package/lib/global/Intelligence/AIAssistant/Chat/ChatRefDocs/index.d.ts +5 -0
  11. package/lib/global/Intelligence/AIAssistant/Chat/ChatRefDocs/index.js +16 -0
  12. package/lib/global/Intelligence/AIAssistant/Chat/ThinkingProcess/index.d.ts +4 -0
  13. package/lib/global/Intelligence/AIAssistant/Chat/ThinkingProcess/index.js +6 -0
  14. package/lib/global/Intelligence/AIAssistant/Chat/index.d.ts +7 -0
  15. package/lib/global/Intelligence/AIAssistant/Chat/index.js +8 -0
  16. package/lib/global/Intelligence/AIAssistant/Preamble/ApiErrorAlert/index.d.ts +5 -0
  17. package/lib/global/Intelligence/AIAssistant/Preamble/ApiErrorAlert/index.js +22 -0
  18. package/lib/global/Intelligence/AIAssistant/Preamble/Button/index.d.ts +8 -0
  19. package/lib/global/Intelligence/AIAssistant/Preamble/Button/index.js +5 -0
  20. package/lib/global/Intelligence/AIAssistant/Preamble/CaptchaInput/index.d.ts +10 -0
  21. package/lib/global/Intelligence/AIAssistant/Preamble/CaptchaInput/index.js +14 -0
  22. package/lib/global/Intelligence/AIAssistant/Preamble/FocusInput/index.d.ts +6 -0
  23. package/lib/global/Intelligence/AIAssistant/Preamble/FocusInput/index.js +19 -0
  24. package/lib/global/Intelligence/AIAssistant/Preamble/FormItem/index.d.ts +16 -0
  25. package/lib/global/Intelligence/AIAssistant/Preamble/FormItem/index.js +27 -0
  26. package/lib/global/Intelligence/AIAssistant/Preamble/Input/index.d.ts +7 -0
  27. package/lib/global/Intelligence/AIAssistant/Preamble/Input/index.js +5 -0
  28. package/lib/global/Intelligence/AIAssistant/Preamble/LoginForm/index.d.ts +3 -0
  29. package/lib/global/Intelligence/AIAssistant/Preamble/LoginForm/index.js +88 -0
  30. package/lib/global/Intelligence/AIAssistant/Preamble/LoginForm/types.d.ts +18 -0
  31. package/lib/global/Intelligence/AIAssistant/Preamble/LoginForm/types.js +1 -0
  32. package/lib/global/Intelligence/AIAssistant/Preamble/LoginForm/utils.d.ts +3 -0
  33. package/lib/global/Intelligence/AIAssistant/Preamble/LoginForm/utils.js +7 -0
  34. package/lib/global/Intelligence/AIAssistant/Preamble/Radio/Radio.d.ts +7 -0
  35. package/lib/global/Intelligence/AIAssistant/Preamble/Radio/Radio.js +11 -0
  36. package/lib/global/Intelligence/AIAssistant/Preamble/Radio/RadioGroup.d.ts +11 -0
  37. package/lib/global/Intelligence/AIAssistant/Preamble/Radio/RadioGroup.js +21 -0
  38. package/lib/global/Intelligence/AIAssistant/Preamble/Radio/context.d.ts +7 -0
  39. package/lib/global/Intelligence/AIAssistant/Preamble/Radio/context.js +2 -0
  40. package/lib/global/Intelligence/AIAssistant/Preamble/Radio/index.d.ts +2 -0
  41. package/lib/global/Intelligence/AIAssistant/Preamble/Radio/index.js +2 -0
  42. package/lib/global/Intelligence/AIAssistant/Preamble/index.d.ts +4 -0
  43. package/lib/global/Intelligence/AIAssistant/Preamble/index.js +10 -0
  44. package/lib/global/Intelligence/AIAssistant/Preamble/types.d.ts +9 -0
  45. package/lib/global/Intelligence/AIAssistant/Preamble/types.js +1 -0
  46. package/lib/global/Intelligence/AIAssistant/ResizableUserInput/index.d.ts +8 -0
  47. package/lib/global/Intelligence/AIAssistant/ResizableUserInput/index.js +54 -0
  48. package/lib/global/Intelligence/AIAssistant/Thinking.d.ts +1 -0
  49. package/lib/global/Intelligence/AIAssistant/Thinking.js +15 -0
  50. package/lib/global/Intelligence/AIAssistant/index.d.ts +6 -0
  51. package/lib/global/Intelligence/AIAssistant/index.js +122 -0
  52. package/lib/global/Intelligence/AIAssistant/types.d.ts +14 -0
  53. package/lib/global/Intelligence/AIAssistant/types.js +1 -0
  54. package/lib/global/Intelligence/AIAssistant/utils.d.ts +8 -0
  55. package/lib/global/Intelligence/AIAssistant/utils.js +29 -0
  56. package/lib/global/Intelligence/constants.d.ts +6 -0
  57. package/lib/global/Intelligence/constants.js +21 -0
  58. package/lib/global/Intelligence/context.d.ts +18 -0
  59. package/lib/global/Intelligence/context.js +31 -0
  60. package/lib/global/Intelligence/index.d.ts +2 -0
  61. package/lib/global/Intelligence/index.js +32 -0
  62. package/lib/global/Intelligence/types.d.ts +32 -0
  63. package/lib/global/Intelligence/types.js +6 -0
  64. package/lib/global/Intelligence/utils.d.ts +3 -0
  65. package/lib/global/Intelligence/utils.js +32 -0
  66. package/lib/global/VersionsNav/NavMenuSingleItem.js +2 -2
  67. package/lib/runtime/hooks/index.d.ts +5 -3
  68. package/lib/runtime/hooks/index.js +5 -3
  69. package/lib/runtime/hooks/useInterval.d.ts +1 -0
  70. package/lib/runtime/hooks/useInterval.js +19 -0
  71. package/lib/runtime/hooks/useMemoizedFn.d.ts +1 -0
  72. package/lib/runtime/hooks/useMemoizedFn.js +12 -0
  73. package/lib/runtime/hooks/useTranslation.d.ts +1 -1
  74. package/lib/runtime/translation.d.ts +148 -0
  75. package/lib/runtime/translation.js +111 -0
  76. package/package.json +10 -5
  77. package/styles/ai-assistant.module.scss +43 -0
  78. package/styles/chat-ref-docs.module.scss +50 -0
  79. package/styles/chat.module.scss +72 -0
  80. package/styles/global.scss +2 -0
  81. package/styles/intelligence.scss +213 -0
  82. package/styles/preamble.module.scss +27 -0
  83. package/styles/resizable-user-input.module.scss +60 -0
@@ -0,0 +1,122 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { clsx } from 'clsx';
3
+ import { useRef, useState } from 'react';
4
+ import { Tooltip } from 'react-tooltip';
5
+ import { ApiMethod, xfetch } from 'x-fetch';
6
+ import { useCloudAuth } from "../context.js";
7
+ import { Chat } from "./Chat/index.js";
8
+ import { Preamble } from "./Preamble/index.js";
9
+ import { ResizableUserInput } from "./ResizableUserInput/index.js";
10
+ import { Thinking } from "./Thinking.js";
11
+ import { parseStreamContent } from "./utils.js";
12
+ import CloseIcon from '@alauda/doom/assets/close.svg?react';
13
+ import LogoutIcon from '@alauda/doom/assets/logout.svg?react';
14
+ import NewChatIcon from '@alauda/doom/assets/new-chat.svg?react';
15
+ import { useMemoizedFn, useTranslation } from '@alauda/doom/runtime';
16
+ import classes from '@alauda/doom/styles/ai-assistant.module.scss';
17
+ const isLoggedIn = (authInfo) => Boolean(authInfo?.detail);
18
+ let textDecoder;
19
+ export const AIAssistant = ({ open, onOpenChange }) => {
20
+ const t = useTranslation();
21
+ const { authInfo, setAuthBasic } = useCloudAuth();
22
+ const loggedIn = isLoggedIn(authInfo);
23
+ const sessionIdRef = useRef(null);
24
+ const [messages, setMessages] = useState([]);
25
+ const chatRef = useRef(null);
26
+ const onNewChat = useMemoizedFn(() => {
27
+ sessionIdRef.current = null;
28
+ setMessages([]);
29
+ });
30
+ const onLogout = useMemoizedFn(() => {
31
+ setAuthBasic();
32
+ onNewChat();
33
+ });
34
+ const onClose = useMemoizedFn(() => {
35
+ onOpenChange(false);
36
+ });
37
+ const flushMessages = useMemoizedFn((setMessagesAction) => {
38
+ setMessages(setMessagesAction);
39
+ setTimeout(() => {
40
+ const chatEl = chatRef.current;
41
+ if (!chatEl) {
42
+ return;
43
+ }
44
+ chatEl.scrollTop = chatEl.scrollHeight;
45
+ }, 200);
46
+ });
47
+ const assistantMessageIndexRef = useRef(-1);
48
+ const onSend_ = async (content) => {
49
+ const assistantMessage = {
50
+ id: Date.now(),
51
+ role: 'assistant',
52
+ content: _jsx(Thinking, {}),
53
+ };
54
+ const index = (assistantMessageIndexRef.current = messages.length + 1);
55
+ flushMessages((messages) => [
56
+ ...messages,
57
+ { id: Date.now(), role: 'user', content },
58
+ assistantMessage,
59
+ ]);
60
+ if (!sessionIdRef.current) {
61
+ const { session_id } = await xfetch('/smart/api/new_session', {
62
+ method: ApiMethod.POST,
63
+ headers: { username: authInfo.detail.user.name },
64
+ });
65
+ sessionIdRef.current = session_id;
66
+ }
67
+ const sessionId = sessionIdRef.current;
68
+ const res = await xfetch('/smart/api/smart_answer', {
69
+ type: null,
70
+ method: ApiMethod.POST,
71
+ body: {
72
+ input_text: content,
73
+ session_id: sessionId,
74
+ },
75
+ });
76
+ textDecoder ??= new TextDecoder();
77
+ let text = '';
78
+ for await (const chunk_ of res.body) {
79
+ if (sessionId !== sessionIdRef.current) {
80
+ break;
81
+ }
82
+ const chunk = textDecoder.decode(chunk_);
83
+ text += chunk
84
+ .replace(/data: (?:\n\n)?/g, '')
85
+ .replace(/(?<!\n)\n\n(?!\n)/g, '')
86
+ .replace(/(?<!\n)\n\n\n\n(?!\n)/g, '\n')
87
+ .replace(/\n{2,}/g, '\n');
88
+ const parsed = parseStreamContent(text);
89
+ if (!parsed.refDocs.length &&
90
+ !parsed.thinkingProcess &&
91
+ !parsed.content) {
92
+ continue;
93
+ }
94
+ flushMessages((messages) => [
95
+ ...messages.slice(0, index),
96
+ { ...messages[index], ...parsed },
97
+ ...messages.slice(index + 1),
98
+ ]);
99
+ }
100
+ };
101
+ const [loading, setLoading] = useState(false);
102
+ const onSend = useMemoizedFn(async (content) => {
103
+ setLoading(true);
104
+ try {
105
+ await onSend_(content);
106
+ }
107
+ catch {
108
+ flushMessages((messages) => {
109
+ const index = assistantMessageIndexRef.current;
110
+ return [
111
+ ...messages.slice(0, index),
112
+ { ...messages[index], content: t('NetworkError') },
113
+ ...messages.slice(index + 1),
114
+ ];
115
+ });
116
+ }
117
+ finally {
118
+ setLoading(false);
119
+ }
120
+ });
121
+ return (_jsxs("div", { className: clsx(classes.container, 'rspress-doc', open && classes.open), children: [_jsxs("div", { className: classes.header, children: [_jsxs("div", { className: classes.title, children: [t('ai_assistant'), loggedIn && (_jsxs(_Fragment, { children: [_jsxs("span", { className: classes.username, children: ["(", authInfo.detail.user.name, ")"] }), _jsx(LogoutIcon, { className: "ai-assistant-logout", onClick: onLogout }), _jsx(Tooltip, { anchorSelect: ".ai-assistant-logout", children: t('logout') })] }))] }), _jsxs("div", { className: classes.icons, children: [messages.length ? (_jsxs(_Fragment, { children: [_jsx(NewChatIcon, { className: "ai-assistant-new-chat", onClick: onNewChat }), _jsx(Tooltip, { anchorSelect: ".ai-assistant-new-chat", children: t('new_chat') })] })) : null, _jsx(CloseIcon, { className: "ai-assistant-close", onClick: onClose }), _jsx(Tooltip, { anchorSelect: ".ai-assistant-close", children: t('close') })] })] }), messages.length ? (_jsx(Chat, { ref: chatRef, messages: messages })) : (_jsx(Preamble, { loggedIn: loggedIn })), loggedIn && _jsx(ResizableUserInput, { loading: loading, onSend: onSend })] }));
122
+ };
@@ -0,0 +1,14 @@
1
+ import type { ReactNode } from 'react';
2
+ export interface RefDoc {
3
+ content: string;
4
+ cos_sim: number;
5
+ id: number;
6
+ path: string;
7
+ }
8
+ export interface ChatMessage {
9
+ id: number;
10
+ role: 'user' | 'assistant';
11
+ content: ReactNode;
12
+ refDocs?: RefDoc[];
13
+ thinkingProcess?: string | null;
14
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ import type { RefDoc } from './types.js';
2
+ export declare const unicodeToString: (unicodeStr: string) => string;
3
+ export declare const removePrefix: (prefix: string | null | undefined, text: string) => string;
4
+ export declare function parseStreamContent(text: string): {
5
+ refDocs: RefDoc[];
6
+ thinkingProcess: string | null | undefined;
7
+ content: string;
8
+ };
@@ -0,0 +1,29 @@
1
+ // based on https://gitlab-ce.alauda.cn/aml/smart-doc/-/blob/master/frontend/src/app/utils/unicode.ts
2
+ import { isObject } from 'es-toolkit/compat';
3
+ export const unicodeToString = (unicodeStr) => unicodeStr.replace(/\\u([0-9a-fA-F]{4})/g, (_match, p1) => String.fromCharCode(Number.parseInt(p1, 16)));
4
+ export const removePrefix = (prefix, text) => (prefix && text.startsWith(prefix) ? text.slice(prefix.length) : text);
5
+ export function parseStreamContent(text) {
6
+ const matchDocs = text.match(/<docs>([\s\S]*?)<\/docs>/);
7
+ const docsReferences = matchDocs?.length
8
+ ? unicodeToString(matchDocs[1])
9
+ : '[]';
10
+ let refDocs = [];
11
+ try {
12
+ refDocs = JSON.parse(docsReferences).filter((r) => isObject(r));
13
+ }
14
+ catch {
15
+ //
16
+ }
17
+ const matchThinks = text.match(/<think>[\s\S]*?<\/think>|^[\s\S]*?<\/think>/g);
18
+ const firstMatched = matchThinks?.[0];
19
+ let matched = firstMatched || matchThinks?.[1];
20
+ if (matched) {
21
+ matched = removePrefix(firstMatched || '', matched);
22
+ }
23
+ const thinkingProcess = matchThinks && matched;
24
+ return {
25
+ refDocs,
26
+ thinkingProcess,
27
+ content: unicodeToString(removePrefix(thinkingProcess, removePrefix(matchDocs?.[0], text))),
28
+ };
29
+ }
@@ -0,0 +1,6 @@
1
+ import type { CloudAuthRegion } from './types.js';
2
+ export declare const CLOUD_AUTH_ORIGIN_KEY = "__CLOUD_AUTH_ORIGIN__";
3
+ export declare const CLOUD_AUTH_TOKEN_KEY = "__CLOUD_AUTH_TOKEN__";
4
+ declare const CLOUD_AUTH_ORIGINS: CloudAuthRegion[];
5
+ export declare const CLOUD_AUTH_ORIGIN_VALUES: string[];
6
+ export { CLOUD_AUTH_ORIGINS };
@@ -0,0 +1,21 @@
1
+ import { isProduction } from '@rspress/shared';
2
+ export const CLOUD_AUTH_ORIGIN_KEY = '__CLOUD_AUTH_ORIGIN__';
3
+ export const CLOUD_AUTH_TOKEN_KEY = '__CLOUD_AUTH_TOKEN__';
4
+ const CLOUD_AUTH_ORIGINS = [
5
+ {
6
+ name: 'global',
7
+ value: 'https://cloud.alauda.io',
8
+ },
9
+ {
10
+ name: 'china',
11
+ value: 'https://cloud.alauda.cn',
12
+ },
13
+ ];
14
+ if (!isProduction()) {
15
+ CLOUD_AUTH_ORIGINS.unshift({
16
+ name: 'local',
17
+ value: '',
18
+ });
19
+ }
20
+ export const CLOUD_AUTH_ORIGIN_VALUES = CLOUD_AUTH_ORIGINS.map(({ value }) => value);
21
+ export { CLOUD_AUTH_ORIGINS };
@@ -0,0 +1,18 @@
1
+ import { type ReactNode } from 'react';
2
+ import type { AuthInfo } from './types.js';
3
+ export interface CloudAuth {
4
+ origin: string;
5
+ detail?: AuthInfo;
6
+ }
7
+ export interface CloudAuthContext {
8
+ authInfo: CloudAuth | null;
9
+ setAuthBasic: (authBasic?: {
10
+ origin: string;
11
+ token: string;
12
+ } | null) => void;
13
+ }
14
+ export declare const CloudAuthContext: import("react").Context<CloudAuthContext>;
15
+ export declare const useCloudAuth: () => CloudAuthContext;
16
+ export declare const CloudAuthProvider: ({ children }: {
17
+ children: ReactNode;
18
+ }) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,31 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext, use, useMemo, useState } from 'react';
3
+ import { CLOUD_AUTH_ORIGIN_KEY, CLOUD_AUTH_TOKEN_KEY } from './constants.js';
4
+ import { getAuthInfoFromToken, setLocalStorage } from './utils.js';
5
+ export const CloudAuthContext = createContext(null);
6
+ export const useCloudAuth = () => use(CloudAuthContext);
7
+ const getCloudAuth = () => {
8
+ const origin = localStorage.getItem(CLOUD_AUTH_ORIGIN_KEY);
9
+ const token = localStorage.getItem(CLOUD_AUTH_TOKEN_KEY);
10
+ if (origin == null) {
11
+ return null;
12
+ }
13
+ if (token == null) {
14
+ return { origin };
15
+ }
16
+ return { origin, detail: getAuthInfoFromToken(token) };
17
+ };
18
+ export const CloudAuthProvider = ({ children }) => {
19
+ const [authInfo, setAuthInfo] = useState(getCloudAuth);
20
+ return (_jsx(CloudAuthContext, { value: useMemo(() => ({
21
+ authInfo,
22
+ setAuthBasic(authBasic) {
23
+ // keep origin in localStorage for next login
24
+ if (authBasic?.origin != null) {
25
+ setLocalStorage(CLOUD_AUTH_ORIGIN_KEY, authBasic.origin);
26
+ }
27
+ setLocalStorage(CLOUD_AUTH_TOKEN_KEY, authBasic?.token);
28
+ setAuthInfo(getCloudAuth);
29
+ },
30
+ }), [authInfo]), children: children }));
31
+ };
@@ -0,0 +1,2 @@
1
+ declare const _default: () => import("react/jsx-runtime").JSX.Element;
2
+ export default _default;
@@ -0,0 +1,32 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { isProduction, NoSSR, useLang } from '@rspress/core/runtime';
3
+ import virtual from 'doom-@global-virtual';
4
+ import { useState } from 'react';
5
+ import { Tooltip } from 'react-tooltip';
6
+ import { ACP_BASE } from "../../shared/index.js";
7
+ import { AIAssistant } from "./AIAssistant/index.js";
8
+ import { CloudAuthProvider } from "./context.js";
9
+ import assistantIcon from '@alauda/doom/assets/assistant.svg';
10
+ import { useMemoizedFn, useTranslation } from '@alauda/doom/runtime';
11
+ const ALLOWED_DOMAINS = new Set(['docs-dev.alauda.cn', 'docs.alauda.io']);
12
+ if (!isProduction()) {
13
+ ALLOWED_DOMAINS.add('localhost');
14
+ }
15
+ const Intelligence_ = () => {
16
+ const t = useTranslation();
17
+ const [open, setOpen] = useState(false);
18
+ const toggleOpen = useMemoizedFn(() => {
19
+ setOpen((prev) => !prev);
20
+ });
21
+ return (_jsxs(CloudAuthProvider, { children: [_jsx(AIAssistant, { open: open, onOpenChange: toggleOpen }), open || (_jsx("button", { type: "button", className: "intelligence-entry", onClick: toggleOpen, children: _jsx("img", { alt: t('ai_assistant'), src: assistantIcon }) })), _jsx(Tooltip, { anchorSelect: ".intelligence-entry", place: "left", children: t('ai_assistant') })] }));
22
+ };
23
+ const Intelligence = () => {
24
+ const lang = useLang();
25
+ if (lang !== 'en' ||
26
+ !ALLOWED_DOMAINS.has(location.hostname) ||
27
+ virtual.userBase !== ACP_BASE) {
28
+ return;
29
+ }
30
+ return _jsx(Intelligence_, {});
31
+ };
32
+ export default () => (_jsx(NoSSR, { children: _jsx(Intelligence, {}) }));
@@ -0,0 +1,32 @@
1
+ export type ValueOf<T> = T[keyof T];
2
+ export declare const TenantType: {
3
+ readonly Alauda: "alauda";
4
+ readonly NONE: "none";
5
+ readonly Tencent: "tencent";
6
+ readonly Huawei: "huawei";
7
+ };
8
+ export type TenantType = ValueOf<typeof TenantType>;
9
+ export type UserType = 'serviceuser' | 'tenantuser';
10
+ export interface AuthTokenInfo {
11
+ tenant_id: string;
12
+ tenant_type: TenantType;
13
+ preferred_username: string;
14
+ email: string;
15
+ user_id: string;
16
+ user_type: UserType;
17
+ }
18
+ export interface AuthUser {
19
+ id: string;
20
+ name: string;
21
+ type: UserType;
22
+ internal: boolean;
23
+ }
24
+ export interface AuthInfo {
25
+ type: TenantType;
26
+ tenant?: string;
27
+ user: AuthUser;
28
+ }
29
+ export interface CloudAuthRegion {
30
+ name: 'global' | 'china' | 'local';
31
+ value: string;
32
+ }
@@ -0,0 +1,6 @@
1
+ export const TenantType = {
2
+ Alauda: 'alauda',
3
+ NONE: 'none',
4
+ Tencent: 'tencent',
5
+ Huawei: 'huawei',
6
+ };
@@ -0,0 +1,3 @@
1
+ import type { AuthInfo } from './types.ts';
2
+ export declare const setLocalStorage: (key: string, value?: string) => void;
3
+ export declare const getAuthInfoFromToken: (token?: string | null) => AuthInfo | undefined;
@@ -0,0 +1,32 @@
1
+ import { decodeUrl } from 'ab64';
2
+ export const setLocalStorage = (key, value) => {
3
+ if (value == null) {
4
+ localStorage.removeItem(key);
5
+ }
6
+ else {
7
+ localStorage.setItem(key, value);
8
+ }
9
+ };
10
+ export const getAuthInfoFromToken = (token) => {
11
+ if (!token) {
12
+ return;
13
+ }
14
+ let authTokenInfo;
15
+ try {
16
+ authTokenInfo = JSON.parse(decodeUrl(token.split('.')[1]));
17
+ }
18
+ catch (err) {
19
+ console.error('jwt decode failed:', err);
20
+ return;
21
+ }
22
+ return {
23
+ type: authTokenInfo.tenant_type,
24
+ tenant: authTokenInfo.tenant_id,
25
+ user: {
26
+ id: authTokenInfo.user_id,
27
+ name: authTokenInfo.preferred_username || authTokenInfo.email,
28
+ type: authTokenInfo.user_type,
29
+ internal: authTokenInfo.user_type === 'serviceuser',
30
+ },
31
+ };
32
+ };
@@ -2,8 +2,8 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Tag } from '@rspress/core/theme';
3
3
  import { isExternalUrl } from '@rspress/shared';
4
4
  import { useMemo } from 'react';
5
- import styles from '../../../styles/versions-nav.module.scss';
6
- import { withoutBase } from '../../shared/index.js';
5
+ import { withoutBase } from "../../shared/index.js";
6
+ import styles from '@alauda/doom/styles/versions-nav.module.scss';
7
7
  export function NavMenuSingleItem({ activeMatch, base, compact, download, link, pathname, rightIcon, text, tag, }) {
8
8
  const isActive = useMemo(() => !!base &&
9
9
  !!pathname &&
@@ -1,3 +1,5 @@
1
- export * from './useIsPrint.js';
2
- export * from './useSiteOverrides.js';
3
- export * from './useTranslation.js';
1
+ export * from './useInterval.ts';
2
+ export * from './useIsPrint.ts';
3
+ export * from './useMemoizedFn.ts';
4
+ export * from './useSiteOverrides.ts';
5
+ export * from './useTranslation.ts';
@@ -1,3 +1,5 @@
1
- export * from './useIsPrint.js';
2
- export * from './useSiteOverrides.js';
3
- export * from './useTranslation.js';
1
+ export * from "./useInterval.js";
2
+ export * from "./useIsPrint.js";
3
+ export * from "./useMemoizedFn.js";
4
+ export * from "./useSiteOverrides.js";
5
+ export * from "./useTranslation.js";
@@ -0,0 +1 @@
1
+ export declare function useInterval(cb: () => void, delay?: number | null): void;
@@ -0,0 +1,19 @@
1
+ import { useEffect, useRef } from 'react';
2
+ export function useInterval(cb, delay) {
3
+ const cbRef = useRef(cb);
4
+ // Remember the latest callback.
5
+ cbRef.current = cb;
6
+ // Set up the interval.
7
+ useEffect(() => {
8
+ if (delay != null) {
9
+ const id = setInterval(
10
+ // ! do not try to refactor as `cbRef.current!` here! `cbRef.current` may change on each tick
11
+ () => {
12
+ cbRef.current();
13
+ }, delay);
14
+ return () => {
15
+ clearInterval(id);
16
+ };
17
+ }
18
+ }, [delay]);
19
+ }
@@ -0,0 +1 @@
1
+ export declare const useMemoizedFn: <T extends (...args: any[]) => any>(fn: T) => T;
@@ -0,0 +1,12 @@
1
+ import { useCallback, useRef } from 'react';
2
+ export const useMemoizedFn =
3
+ /* eslint-disable @typescript-eslint/no-explicit-any */
4
+ // type-coverage:ignore-next-line
5
+ (fn) => {
6
+ /* eslint-enable @typescript-eslint/no-explicit-any */
7
+ const fnRef = useRef(fn);
8
+ fnRef.current = fn;
9
+ return useCallback(
10
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
11
+ (...args) => fnRef.current(...args), []);
12
+ };
@@ -1,3 +1,3 @@
1
1
  import type { Language } from '../../shared/index.js';
2
2
  export declare const useLang: () => Language;
3
- export declare const useTranslation: () => (key: "function" | "name" | "description" | "delete" | "toc" | "create" | "update" | "collapse_all" | "expand_all" | "crd_no_schema" | "action" | "view" | "chinese" | "english" | "chinese_bad_cases" | "english_bad_cases" | "download_pdf" | "view_docs_as_pdf") => string;
3
+ export declare const useTranslation: () => (key: "function" | "name" | "description" | "delete" | "toc" | "create" | "update" | "close" | "collapse_all" | "expand_all" | "crd_no_schema" | "action" | "view" | "chinese" | "english" | "chinese_bad_cases" | "english_bad_cases" | "download_pdf" | "view_docs_as_pdf" | "ai_assistant" | "exclamation" | "semicolon" | "period" | "colon" | "user_login" | "user_login_tip" | "customer_portal_global" | "customer_portal_china" | "user_login_region_china_tip" | "user_login_region_global_tip" | "account_id" | "username" | "password" | "captcha" | "login" | "current_field" | "field_required" | "ERR_INTERNET_DISCONNECTED" | "AccountDisabledError" | "CaptchaError" | "LoginError" | "NetworkError" | "TenantError" | "TenantNotFoundError" | "logout" | "hi_there" | "ai_assistant_tip" | "ai_assistant_placeholder" | "max_chars_exceeded_tip" | "thinking" | "thinking_process" | "referenced_doc_links" | "view_more_related_docs" | "view_less_related_docs" | "new_chat") => string;
@@ -17,6 +17,43 @@ declare const en: {
17
17
  download_pdf: string;
18
18
  toc: string;
19
19
  view_docs_as_pdf: string;
20
+ ai_assistant: string;
21
+ close: string;
22
+ exclamation: string;
23
+ semicolon: string;
24
+ period: string;
25
+ colon: string;
26
+ user_login: string;
27
+ user_login_tip: string;
28
+ customer_portal_global: string;
29
+ customer_portal_china: string;
30
+ user_login_region_china_tip: string;
31
+ user_login_region_global_tip: string;
32
+ account_id: string;
33
+ username: string;
34
+ password: string;
35
+ captcha: string;
36
+ login: string;
37
+ current_field: string;
38
+ field_required: string;
39
+ ERR_INTERNET_DISCONNECTED: string;
40
+ AccountDisabledError: string;
41
+ CaptchaError: string;
42
+ LoginError: string;
43
+ NetworkError: string;
44
+ TenantError: string;
45
+ TenantNotFoundError: string;
46
+ logout: string;
47
+ hi_there: string;
48
+ ai_assistant_tip: string;
49
+ ai_assistant_placeholder: string;
50
+ max_chars_exceeded_tip: string;
51
+ thinking: string;
52
+ thinking_process: string;
53
+ referenced_doc_links: string;
54
+ view_more_related_docs: string;
55
+ view_less_related_docs: string;
56
+ new_chat: string;
20
57
  };
21
58
  export type Translation = typeof en;
22
59
  export declare const TRANSLATIONS: {
@@ -39,6 +76,43 @@ export declare const TRANSLATIONS: {
39
76
  download_pdf: string;
40
77
  toc: string;
41
78
  view_docs_as_pdf: string;
79
+ ai_assistant: string;
80
+ close: string;
81
+ exclamation: string;
82
+ semicolon: string;
83
+ period: string;
84
+ colon: string;
85
+ user_login: string;
86
+ user_login_tip: string;
87
+ customer_portal_global: string;
88
+ customer_portal_china: string;
89
+ user_login_region_china_tip: string;
90
+ user_login_region_global_tip: string;
91
+ account_id: string;
92
+ username: string;
93
+ password: string;
94
+ captcha: string;
95
+ login: string;
96
+ current_field: string;
97
+ field_required: string;
98
+ ERR_INTERNET_DISCONNECTED: string;
99
+ AccountDisabledError: string;
100
+ CaptchaError: string;
101
+ LoginError: string;
102
+ NetworkError: string;
103
+ TenantError: string;
104
+ TenantNotFoundError: string;
105
+ logout: string;
106
+ hi_there: string;
107
+ ai_assistant_tip: string;
108
+ ai_assistant_placeholder: string;
109
+ max_chars_exceeded_tip: string;
110
+ thinking: string;
111
+ thinking_process: string;
112
+ referenced_doc_links: string;
113
+ view_more_related_docs: string;
114
+ view_less_related_docs: string;
115
+ new_chat: string;
42
116
  };
43
117
  zh: {
44
118
  collapse_all: string;
@@ -59,6 +133,43 @@ export declare const TRANSLATIONS: {
59
133
  download_pdf: string;
60
134
  toc: string;
61
135
  view_docs_as_pdf: string;
136
+ ai_assistant: string;
137
+ close: string;
138
+ exclamation: string;
139
+ semicolon: string;
140
+ period: string;
141
+ colon: string;
142
+ user_login: string;
143
+ user_login_tip: string;
144
+ customer_portal_global: string;
145
+ customer_portal_china: string;
146
+ user_login_region_china_tip: string;
147
+ user_login_region_global_tip: string;
148
+ account_id: string;
149
+ username: string;
150
+ password: string;
151
+ captcha: string;
152
+ login: string;
153
+ current_field: string;
154
+ field_required: string;
155
+ ERR_INTERNET_DISCONNECTED: string;
156
+ AccountDisabledError: string;
157
+ CaptchaError: string;
158
+ LoginError: string;
159
+ NetworkError: string;
160
+ TenantError: string;
161
+ TenantNotFoundError: string;
162
+ logout: string;
163
+ hi_there: string;
164
+ ai_assistant_tip: string;
165
+ ai_assistant_placeholder: string;
166
+ max_chars_exceeded_tip: string;
167
+ thinking: string;
168
+ thinking_process: string;
169
+ referenced_doc_links: string;
170
+ view_more_related_docs: string;
171
+ view_less_related_docs: string;
172
+ new_chat: string;
62
173
  };
63
174
  ru: {
64
175
  collapse_all: string;
@@ -79,6 +190,43 @@ export declare const TRANSLATIONS: {
79
190
  download_pdf: string;
80
191
  toc: string;
81
192
  view_docs_as_pdf: string;
193
+ ai_assistant: string;
194
+ close: string;
195
+ exclamation: string;
196
+ semicolon: string;
197
+ period: string;
198
+ colon: string;
199
+ user_login: string;
200
+ user_login_tip: string;
201
+ customer_portal_global: string;
202
+ customer_portal_china: string;
203
+ user_login_region_china_tip: string;
204
+ user_login_region_global_tip: string;
205
+ account_id: string;
206
+ username: string;
207
+ password: string;
208
+ captcha: string;
209
+ login: string;
210
+ current_field: string;
211
+ field_required: string;
212
+ ERR_INTERNET_DISCONNECTED: string;
213
+ AccountDisabledError: string;
214
+ CaptchaError: string;
215
+ LoginError: string;
216
+ NetworkError: string;
217
+ TenantError: string;
218
+ TenantNotFoundError: string;
219
+ logout: string;
220
+ hi_there: string;
221
+ ai_assistant_tip: string;
222
+ ai_assistant_placeholder: string;
223
+ max_chars_exceeded_tip: string;
224
+ thinking: string;
225
+ thinking_process: string;
226
+ referenced_doc_links: string;
227
+ view_more_related_docs: string;
228
+ view_less_related_docs: string;
229
+ new_chat: string;
82
230
  };
83
231
  };
84
232
  export {};