@alauda/doom 1.10.12 → 1.12.0

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 (155) 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/export.js +1 -1
  10. package/lib/cli/load-config.js +11 -6
  11. package/lib/global/Intelligence/AIAssistant/Chat/ChatRefDocs/index.d.ts +5 -0
  12. package/lib/global/Intelligence/AIAssistant/Chat/ChatRefDocs/index.js +16 -0
  13. package/lib/global/Intelligence/AIAssistant/Chat/ThinkingProcess/index.d.ts +4 -0
  14. package/lib/global/Intelligence/AIAssistant/Chat/ThinkingProcess/index.js +6 -0
  15. package/lib/global/Intelligence/AIAssistant/Chat/index.d.ts +7 -0
  16. package/lib/global/Intelligence/AIAssistant/Chat/index.js +8 -0
  17. package/lib/global/Intelligence/AIAssistant/Preamble/ApiErrorAlert/index.d.ts +5 -0
  18. package/lib/global/Intelligence/AIAssistant/Preamble/ApiErrorAlert/index.js +22 -0
  19. package/lib/global/Intelligence/AIAssistant/Preamble/Button/index.d.ts +8 -0
  20. package/lib/global/Intelligence/AIAssistant/Preamble/Button/index.js +5 -0
  21. package/lib/global/Intelligence/AIAssistant/Preamble/CaptchaInput/index.d.ts +10 -0
  22. package/lib/global/Intelligence/AIAssistant/Preamble/CaptchaInput/index.js +14 -0
  23. package/lib/global/Intelligence/AIAssistant/Preamble/FocusInput/index.d.ts +6 -0
  24. package/lib/global/Intelligence/AIAssistant/Preamble/FocusInput/index.js +19 -0
  25. package/lib/global/Intelligence/AIAssistant/Preamble/FormItem/index.d.ts +16 -0
  26. package/lib/global/Intelligence/AIAssistant/Preamble/FormItem/index.js +27 -0
  27. package/lib/global/Intelligence/AIAssistant/Preamble/Input/index.d.ts +7 -0
  28. package/lib/global/Intelligence/AIAssistant/Preamble/Input/index.js +5 -0
  29. package/lib/global/Intelligence/AIAssistant/Preamble/LoginForm/index.d.ts +3 -0
  30. package/lib/global/Intelligence/AIAssistant/Preamble/LoginForm/index.js +88 -0
  31. package/lib/global/Intelligence/AIAssistant/Preamble/LoginForm/types.d.ts +18 -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 +33 -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/plugins/index.d.ts +0 -1
  68. package/lib/plugins/index.js +0 -1
  69. package/lib/runtime/components/OpenAPIPath.js +2 -3
  70. package/lib/runtime/components/Overview.js +3 -6
  71. package/lib/runtime/components/_utils.d.ts +1 -1
  72. package/lib/runtime/components/_utils.js +2 -4
  73. package/lib/runtime/hooks/index.d.ts +5 -3
  74. package/lib/runtime/hooks/index.js +5 -3
  75. package/lib/runtime/hooks/useInterval.d.ts +1 -0
  76. package/lib/runtime/hooks/useInterval.js +19 -0
  77. package/lib/runtime/hooks/useMemoizedFn.d.ts +1 -0
  78. package/lib/runtime/hooks/useMemoizedFn.js +12 -0
  79. package/lib/runtime/hooks/useTranslation.d.ts +1 -1
  80. package/lib/runtime/translation.d.ts +148 -0
  81. package/lib/runtime/translation.js +111 -0
  82. package/package.json +32 -30
  83. package/styles/ai-assistant.module.scss +61 -0
  84. package/styles/chat-ref-docs.module.scss +50 -0
  85. package/styles/chat.module.scss +72 -0
  86. package/styles/global.scss +2 -0
  87. package/styles/intelligence.module.scss +26 -0
  88. package/styles/intelligence.scss +168 -0
  89. package/styles/preamble.module.scss +27 -0
  90. package/styles/resizable-user-input.module.scss +60 -0
  91. package/LICENSE +0 -21
  92. package/README.md +0 -29
  93. package/lib/cli/export-pdf-core/generatePdf.d.ts +0 -25
  94. package/lib/cli/export-pdf-core/generatePdf.js +0 -91
  95. package/lib/cli/export-pdf-core/index.d.ts +0 -3
  96. package/lib/cli/export-pdf-core/index.js +0 -3
  97. package/lib/cli/export-pdf-core/types.d.ts +0 -15
  98. package/lib/cli/export-pdf-core/utils/convertPathToPosix.d.ts +0 -8
  99. package/lib/cli/export-pdf-core/utils/convertPathToPosix.js +0 -26
  100. package/lib/cli/export-pdf-core/utils/getUrlLink.d.ts +0 -4
  101. package/lib/cli/export-pdf-core/utils/getUrlLink.js +0 -7
  102. package/lib/cli/export-pdf-core/utils/index.d.ts +0 -3
  103. package/lib/cli/export-pdf-core/utils/index.js +0 -3
  104. package/lib/cli/export-pdf-core/utils/mergePDF.d.ts +0 -26
  105. package/lib/cli/export-pdf-core/utils/mergePDF.js +0 -137
  106. package/lib/cli/html-export-pdf/core/index.d.ts +0 -3
  107. package/lib/cli/html-export-pdf/core/index.js +0 -3
  108. package/lib/cli/html-export-pdf/core/outline.d.ts +0 -47
  109. package/lib/cli/html-export-pdf/core/outline.js +0 -217
  110. package/lib/cli/html-export-pdf/core/postprocesser.d.ts +0 -14
  111. package/lib/cli/html-export-pdf/core/postprocesser.js +0 -36
  112. package/lib/cli/html-export-pdf/core/printer.d.ts +0 -59
  113. package/lib/cli/html-export-pdf/core/printer.js +0 -235
  114. package/lib/cli/html-export-pdf/index.d.ts +0 -2
  115. package/lib/cli/html-export-pdf/index.js +0 -2
  116. package/lib/cli/html-export-pdf/utils/cliProgress.d.ts +0 -13
  117. package/lib/cli/html-export-pdf/utils/cliProgress.js +0 -80
  118. package/lib/cli/html-export-pdf/utils/fs.d.ts +0 -5
  119. package/lib/cli/html-export-pdf/utils/fs.js +0 -18
  120. package/lib/cli/html-export-pdf/utils/getAbsFileName.d.ts +0 -1
  121. package/lib/cli/html-export-pdf/utils/getAbsFileName.js +0 -4
  122. package/lib/cli/html-export-pdf/utils/getDirname.d.ts +0 -1
  123. package/lib/cli/html-export-pdf/utils/getDirname.js +0 -5
  124. package/lib/cli/html-export-pdf/utils/index.d.ts +0 -7
  125. package/lib/cli/html-export-pdf/utils/index.js +0 -7
  126. package/lib/cli/html-export-pdf/utils/isValidUrl.d.ts +0 -1
  127. package/lib/cli/html-export-pdf/utils/isValidUrl.js +0 -3
  128. package/lib/cli/html-export-pdf/utils/optionsCustomProcessing.d.ts +0 -2
  129. package/lib/cli/html-export-pdf/utils/optionsCustomProcessing.js +0 -6
  130. package/lib/cli/html-export-pdf/utils/replaceExt.d.ts +0 -1
  131. package/lib/cli/html-export-pdf/utils/replaceExt.js +0 -19
  132. package/lib/cli/merge-pdfs/formatDate.d.ts +0 -1
  133. package/lib/cli/merge-pdfs/formatDate.js +0 -23
  134. package/lib/cli/merge-pdfs/index.d.ts +0 -8
  135. package/lib/cli/merge-pdfs/index.js +0 -62
  136. package/lib/plugins/sitemap/index.d.ts +0 -16
  137. package/lib/plugins/sitemap/index.js +0 -51
  138. package/pyodide/README.md +0 -90
  139. package/pyodide/console.html +0 -259
  140. package/pyodide/ffi.d.ts +0 -1118
  141. package/pyodide/micropip-0.8.0-py3-none-any.whl +0 -0
  142. package/pyodide/package.json +0 -59
  143. package/pyodide/packaging-24.2-py3-none-any.whl +0 -0
  144. package/pyodide/pyodide-lock.json +0 -1
  145. package/pyodide/pyodide.asm.js +0 -17
  146. package/pyodide/pyodide.asm.wasm +0 -0
  147. package/pyodide/pyodide.d.ts +0 -1627
  148. package/pyodide/pyodide.js +0 -6
  149. package/pyodide/pyodide.js.map +0 -1
  150. package/pyodide/pyodide.mjs +0 -4
  151. package/pyodide/pyodide.mjs.map +0 -1
  152. package/pyodide/pypdf-3.8.1-py3-none-any.whl +0 -0
  153. package/pyodide/python_stdlib.zip +0 -0
  154. package/pyodide/repodata.json +0 -1
  155. /package/lib/{cli/export-pdf-core → global/Intelligence/AIAssistant/Preamble/LoginForm}/types.js +0 -0
@@ -0,0 +1,54 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { clsx } from 'clsx';
3
+ import { useMemo, useState, } from 'react';
4
+ import stringWidth from 'string-width';
5
+ import SendIcon from '@alauda/doom/assets/send.svg?react';
6
+ import { useMemoizedFn, useTranslation } from '@alauda/doom/runtime';
7
+ import classes from '@alauda/doom/styles/resizable-user-input.module.scss';
8
+ export const ResizableUserInput = ({ value, loading, onChange, onSend, }) => {
9
+ const t = useTranslation();
10
+ const [innerValue, setInnerValue] = useState(value ?? '');
11
+ if (value != null && innerValue !== value) {
12
+ setInnerValue(value);
13
+ }
14
+ const maxCharsExceeded = innerValue.length > 2000;
15
+ const isSendDisabled = useMemo(() => loading || maxCharsExceeded || !innerValue.trim(), [loading, maxCharsExceeded, innerValue]);
16
+ const handleSend = useMemoizedFn(() => {
17
+ if (isSendDisabled) {
18
+ return;
19
+ }
20
+ const content = innerValue.trim();
21
+ if (!content) {
22
+ return;
23
+ }
24
+ onSend?.(content);
25
+ setInnerValue('');
26
+ });
27
+ const handleChange = useMemoizedFn((ev) => {
28
+ const value = ev.target.value;
29
+ onChange?.(value);
30
+ setInnerValue(value);
31
+ });
32
+ const onKeyDown = useMemoizedFn((ev) => {
33
+ ev.stopPropagation();
34
+ const event = ev.nativeEvent;
35
+ if (ev.key === 'Enter' &&
36
+ !event.isComposing &&
37
+ !ev.altKey &&
38
+ !ev.ctrlKey &&
39
+ !ev.metaKey &&
40
+ !ev.shiftKey) {
41
+ ev.preventDefault();
42
+ handleSend();
43
+ }
44
+ });
45
+ const textLines = useMemo(() => innerValue
46
+ .split(/\r?\n/)
47
+ .map((line) => Math.ceil(stringWidth(line) / /* 27 Chinese characters */ 54))
48
+ .reduce((acc, curr) => acc + curr, 0), [innerValue]);
49
+ const inputHeight = useMemo(() => Math.min(Math.max(textLines, 3), 8) * 20, [textLines]);
50
+ const inputStyle = useMemo(() => ({
51
+ minHeight: inputHeight,
52
+ }), [inputHeight]);
53
+ return (_jsxs("div", { className: clsx(classes.input, maxCharsExceeded && classes.error), children: [_jsx("textarea", { placeholder: t('ai_assistant_placeholder'), value: innerValue, onChange: handleChange, onKeyDown: onKeyDown, style: inputStyle }), _jsxs("div", { className: classes.actions, children: [_jsx(SendIcon, { className: clsx(classes.send, isSendDisabled && classes.disabled), onClick: handleSend }), maxCharsExceeded && (_jsx("span", { className: classes.errorTip, children: t('max_chars_exceeded_tip') }))] })] }));
54
+ };
@@ -0,0 +1 @@
1
+ export declare const Thinking: () => string;
@@ -0,0 +1,15 @@
1
+ import { useState } from 'react';
2
+ import { useInterval, useTranslation } from '@alauda/doom/runtime';
3
+ const CHUNKS = ['', '.', '..', '...'];
4
+ const CHUNKS_LENGTH = CHUNKS.length;
5
+ export const Thinking = () => {
6
+ const t = useTranslation();
7
+ const [index, setIndex] = useState(0);
8
+ useInterval(() => {
9
+ setIndex((index) => {
10
+ const nextIndex = index + 1;
11
+ return nextIndex === CHUNKS_LENGTH ? 0 : nextIndex;
12
+ });
13
+ }, 250);
14
+ return `${t('thinking')}${CHUNKS[index]}`;
15
+ };
@@ -0,0 +1,6 @@
1
+ export interface AIAssistantProps {
2
+ open?: boolean;
3
+ onOpenChange: (open: boolean) => void;
4
+ onCleanup?: () => void;
5
+ }
6
+ export declare const AIAssistant: ({ open, onOpenChange }: AIAssistantProps) => import("react/jsx-runtime").JSX.Element;
@@ -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: classes.logout, onClick: onLogout }), _jsx(Tooltip, { anchorSelect: `.${classes.logout}`, children: t('logout') })] }))] }), _jsxs("div", { className: classes.icons, children: [messages.length ? (_jsxs(_Fragment, { children: [_jsx(NewChatIcon, { className: classes.newChat, onClick: onNewChat }), _jsx(Tooltip, { anchorSelect: `.${classes.newChat}`, children: t('new_chat') })] })) : null, _jsx(CloseIcon, { className: classes.close, onClick: onClose }), _jsx(Tooltip, { anchorSelect: `.${classes.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,33 @@
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
+ import classes from '@alauda/doom/styles/intelligence.module.scss';
12
+ const ALLOWED_DOMAINS = new Set(['docs-dev.alauda.cn', 'docs.alauda.io']);
13
+ if (!isProduction()) {
14
+ ALLOWED_DOMAINS.add('localhost');
15
+ }
16
+ const Intelligence_ = () => {
17
+ const t = useTranslation();
18
+ const [open, setOpen] = useState(false);
19
+ const toggleOpen = useMemoizedFn(() => {
20
+ setOpen((prev) => !prev);
21
+ });
22
+ return (_jsxs(CloudAuthProvider, { children: [_jsx(AIAssistant, { open: open, onOpenChange: toggleOpen }), open || (_jsx("button", { type: "button", className: classes.entry, onClick: toggleOpen, children: _jsx("img", { alt: t('ai_assistant'), src: assistantIcon }) })), _jsx(Tooltip, { anchorSelect: `.${classes.entry}`, place: "left", children: t('ai_assistant') })] }));
23
+ };
24
+ const Intelligence = () => {
25
+ const lang = useLang();
26
+ if (lang !== 'en' ||
27
+ !ALLOWED_DOMAINS.has(location.hostname) ||
28
+ virtual.userBase !== ACP_BASE) {
29
+ return;
30
+ }
31
+ return _jsx(Intelligence_, {});
32
+ };
33
+ 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 &&
@@ -7,4 +7,3 @@ export * from './mermaid/index.js';
7
7
  export * from './permission/index.js';
8
8
  export * from './replace/index.js';
9
9
  export * from './shiki/index.js';
10
- export * from './sitemap/index.js';
@@ -7,4 +7,3 @@ export * from './mermaid/index.js';
7
7
  export * from './permission/index.js';
8
8
  export * from './replace/index.js';
9
9
  export * from './shiki/index.js';
10
- export * from './sitemap/index.js';
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { usePageData } from '@rspress/core/runtime';
2
+ import { usePage } from '@rspress/core/runtime';
3
3
  import { Badge } from '@rspress/core/theme';
4
4
  import openapisMap from 'doom-@api-openapisMap';
5
5
  import virtual from 'doom-@api-virtual';
@@ -92,8 +92,7 @@ const getRefsForPath = (openapi, path, knownRefs) => {
92
92
  return Array.from(refs);
93
93
  };
94
94
  export const OpenAPIPath = ({ path, openapiPath: openapiPath_, pathPrefix: pathPrefix_, }) => {
95
- // eslint-disable-next-line @typescript-eslint/no-deprecated -- `usePage` is not exported...
96
- const { page } = usePageData();
95
+ const { page } = usePage();
97
96
  const pathPrefix = pathPrefix_ ?? (virtual.pathPrefix || '');
98
97
  const uid = useId();
99
98
  const slugger = useMemo(() => new BananaSlug(), []);
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { isEqualPath, normalizeHrefInRuntime as normalizeHref, usePageData, useSidebar, } from '@rspress/core/runtime';
2
+ import { isEqualPath, usePageData, useSidebar } from '@rspress/core/runtime';
3
3
  import { Link, renderInlineMarkdown } from '@rspress/core/theme';
4
4
  import { Fragment, useCallback, useMemo } from 'react';
5
5
  import classes from '../../../styles/overview.module.scss';
@@ -19,10 +19,7 @@ const getChildLink = (traverseItem) => {
19
19
  export function Overview(props) {
20
20
  const { siteData, page: { routePath, frontmatter, title }, } = usePageData();
21
21
  const { content, groups: customGroups, defaultGroupTitle = 'Others' } = props;
22
- const subFilter = useCallback((link) =>
23
- // sidebar items link without base path
24
- // pages route path with base path
25
- link.startsWith(routePath.replace(/overview$/, '')) &&
22
+ const subFilter = useCallback((link) => link.startsWith(routePath.replace(/overview$/, '')) &&
26
23
  !isEqualPath(link, routePath), [routePath]);
27
24
  const { pages } = siteData;
28
25
  const overviewModules = useMemo(() => pages.filter((page) => subFilter(page.routePath)), [pages, subFilter]);
@@ -111,6 +108,6 @@ export function Overview(props) {
111
108
  }, [getGroup, overviewSidebarGroups]);
112
109
  const groups = customGroups ?? defaultGroups;
113
110
  return (_jsxs("div", { className: "overview-index doom-overview-index rp-mx-auto", children: [content, groups.map((group) => (_jsxs(Fragment, { children: [(!title || [title, defaultGroupTitle].includes(group.name)) &&
114
- groups.length === 1 ? (_jsx("h2", { style: { paddingTop: 0 } })) : (_jsx("h2", { ...renderInlineMarkdown(group.name) })), _jsx("div", { className: classes.overviewGroups, children: group.items.map((item) => (_jsxs("div", { className: classes.overviewGroup, children: [_jsx("h3", { style: { marginBottom: 8 }, children: _jsx(Link, { href: normalizeHref(item.link), ...renderInlineMarkdown(item.text) }) }), _jsx("div", { className: classes.overviewDescription, children: item.description }), _jsx("ul", { className: "rp-list-none", children: item.headers?.map((header) => (_jsx("li", { className: `${classes.overviewGroupLi} ${classes[`level${header.depth}`]} first:rp-mt-2`, children: _jsx(Link, { href: `${normalizeHref(item.link)}#${header.id}`, ...renderInlineMarkdown(header.text) }) }, header.id))) })] }, item.link))) })] }, group.name)))] }));
111
+ groups.length === 1 ? (_jsx("h2", { style: { paddingTop: 0 } })) : (_jsx("h2", { ...renderInlineMarkdown(group.name) })), _jsx("div", { className: classes.overviewGroups, children: group.items.map((item) => (_jsxs("div", { className: classes.overviewGroup, children: [_jsx("h3", { style: { marginBottom: 8 }, children: _jsx(Link, { href: item.link, ...renderInlineMarkdown(item.text) }) }), _jsx("div", { className: classes.overviewDescription, children: item.description }), _jsx("ul", { className: "rp-list-none", children: item.headers?.map((header) => (_jsx("li", { className: `${classes.overviewGroupLi} ${classes[`level${header.depth}`]} first:rp-mt-2`, children: _jsx(Link, { href: `${item.link}#${header.id}`, ...renderInlineMarkdown(header.text) }) }, header.id))) })] }, item.link))) })] }, group.name)))] }));
115
112
  }
116
113
  export default Overview;
@@ -1,5 +1,5 @@
1
1
  import type { SidebarDivider, SidebarItem, SidebarSectionHeader } from '@rspress/core';
2
- import type { NormalizedSidebarGroup } from '@rspress/shared';
2
+ import { type NormalizedSidebarGroup } from '@rspress/shared';
3
3
  export declare const isSidebarDivider: (item: NormalizedSidebarGroup | SidebarItem | SidebarDivider | SidebarSectionHeader) => item is SidebarDivider;
4
4
  export declare const isSidebarSectionHeader: (item: NormalizedSidebarGroup | SidebarItem | SidebarDivider | SidebarSectionHeader) => item is SidebarSectionHeader;
5
5
  export declare const isSingleFile: (item: SidebarItem | SidebarSectionHeader | SidebarDivider | NormalizedSidebarGroup) => item is SidebarItem | (NormalizedSidebarGroup & {
@@ -1,8 +1,6 @@
1
+ import { normalizeHref } from '@rspress/shared';
1
2
  function removeIndex(link) {
2
- if (link.endsWith('/index')) {
3
- return link.slice(0, -5);
4
- }
5
- return link;
3
+ return normalizeHref(link, true);
6
4
  }
7
5
  export const isSidebarDivider = (item) => {
8
6
  return 'dividerType' in item;
@@ -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;