@alauda/doom 2.3.1 → 2.5.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.
- package/lib/cli/helpers.d.ts +12 -0
- package/lib/cli/helpers.js +58 -1
- package/lib/cli/load-config.js +1 -1
- package/lib/cli/translate.js +25 -39
- package/lib/global/Intelligence/AIAssistant/Chat/ChatRefDocs/index.d.ts +2 -2
- package/lib/global/Intelligence/AIAssistant/Chat/ThinkingProcess/index.js +2 -1
- package/lib/global/Intelligence/AIAssistant/Chat/index.js +1 -1
- package/lib/global/Intelligence/AIAssistant/index.js +21 -55
- package/lib/global/Intelligence/AIAssistant/types.d.ts +3 -8
- package/lib/global/Intelligence/index.js +2 -7
- package/lib/plugins/global/index.js +20 -5
- package/lib/plugins/replace/parse-toc.js +1 -1
- package/lib/products/index.d.ts +15 -0
- package/lib/products/index.js +25 -0
- package/lib/remark-lint/check-dead-links.js +6 -1
- package/lib/runtime/components/ExternalSiteLink.js +3 -2
- package/lib/runtime/components/Markdown.js +0 -1
- package/lib/runtime/components/Masonry.js +0 -1
- package/lib/runtime/components/OpenAPIPath.d.ts +1 -1
- package/lib/runtime/components/OpenAPIPath.js +1 -1
- package/lib/runtime/components/_HeadingTitle.d.ts +1 -1
- package/lib/runtime/components/_HeadingTitle.js +1 -1
- package/lib/runtime/hooks/useSiteOverrides.js +2 -5
- package/lib/runtime/hooks/useTranslation.d.ts +1 -1
- package/lib/runtime/translation.d.ts +12 -0
- package/lib/runtime/translation.js +9 -0
- package/lib/shared/context.d.ts +5 -0
- package/lib/shared/context.js +2 -0
- package/lib/theme/AutoExpandable.js +0 -1
- package/lib/theme/Breadcrumb/index.d.ts +6 -0
- package/lib/theme/Breadcrumb/index.js +85 -0
- package/lib/theme/Layout.js +6 -3
- package/lib/theme/_X.d.ts +23 -0
- package/lib/theme/_X.js +2 -0
- package/package.json +24 -23
- package/styles/_mixins.scss +19 -0
- package/styles/breadcrumb.scss +42 -0
- package/styles/chat-ref-docs.module.scss +4 -0
- package/styles/chat.module.scss +85 -6
- package/styles/global.scss +1 -0
- package/styles/login.module.scss +3 -12
- package/styles/products.module.scss +45 -0
- package/lib/global/Intelligence/AIAssistant/utils.d.ts +0 -19
- package/lib/global/Intelligence/AIAssistant/utils.js +0 -131
|
@@ -1,131 +0,0 @@
|
|
|
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
|
-
const IGNORED_SSE_EVENT_TYPES = /(?:^|[._-])(?:metadata|trace|updates?)(?:$|[._-])/i;
|
|
4
|
-
const STREAM_TEXT_KEYS = ['delta', 'text', 'content', 'answer', 'message'];
|
|
5
|
-
export const unicodeToString = (unicodeStr) => unicodeStr.replace(/\\u([0-9a-fA-F]{4})/g, (_match, p1) => String.fromCharCode(Number.parseInt(p1, 16)));
|
|
6
|
-
const isRecord = (value) => isObject(value) && !Array.isArray(value);
|
|
7
|
-
export const removePrefix = (prefix, text) => (prefix && text.startsWith(prefix) ? text.slice(prefix.length) : text);
|
|
8
|
-
const parseSSEFieldValue = (line, field) => {
|
|
9
|
-
const value = line.slice(field.length + 1);
|
|
10
|
-
return value.startsWith(' ') ? value.slice(1) : value;
|
|
11
|
-
};
|
|
12
|
-
const getStringValue = (value) => {
|
|
13
|
-
if (typeof value === 'string') {
|
|
14
|
-
return value;
|
|
15
|
-
}
|
|
16
|
-
if (Array.isArray(value)) {
|
|
17
|
-
const text = value.map((item) => getStringValue(item) || '').join('');
|
|
18
|
-
return text || undefined;
|
|
19
|
-
}
|
|
20
|
-
if (!isRecord(value)) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
for (const key of STREAM_TEXT_KEYS) {
|
|
24
|
-
const text = getStringValue(value[key]);
|
|
25
|
-
if (text) {
|
|
26
|
-
return text;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
const getChoicesDelta = (choices) => {
|
|
31
|
-
if (!Array.isArray(choices)) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
const text = choices.map((choice) => getStringValue(choice) || '').join('');
|
|
35
|
-
return text || undefined;
|
|
36
|
-
};
|
|
37
|
-
export const consumeSSEEvents = (buffer, event) => {
|
|
38
|
-
const events = [];
|
|
39
|
-
let remaining = buffer;
|
|
40
|
-
let currentEvent = event;
|
|
41
|
-
let lineBoundary = remaining.match(/\r?\n/);
|
|
42
|
-
while (lineBoundary?.index != null) {
|
|
43
|
-
const line = remaining.slice(0, lineBoundary.index);
|
|
44
|
-
remaining = remaining.slice(lineBoundary.index + lineBoundary[0].length);
|
|
45
|
-
if (!line) {
|
|
46
|
-
currentEvent = undefined;
|
|
47
|
-
}
|
|
48
|
-
else if (line.startsWith(':')) {
|
|
49
|
-
//
|
|
50
|
-
}
|
|
51
|
-
else if (line.startsWith('event:')) {
|
|
52
|
-
currentEvent = parseSSEFieldValue(line, 'event');
|
|
53
|
-
}
|
|
54
|
-
else if (line.startsWith('data:')) {
|
|
55
|
-
events.push({
|
|
56
|
-
event: currentEvent,
|
|
57
|
-
data: parseSSEFieldValue(line, 'data'),
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
lineBoundary = remaining.match(/\r?\n/);
|
|
61
|
-
}
|
|
62
|
-
return {
|
|
63
|
-
event: currentEvent,
|
|
64
|
-
events,
|
|
65
|
-
remainder: remaining,
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
export const getAnswerDelta = ({ event, data }) => {
|
|
69
|
-
if (!data || data === '[DONE]') {
|
|
70
|
-
return '';
|
|
71
|
-
}
|
|
72
|
-
if (event && IGNORED_SSE_EVENT_TYPES.test(event)) {
|
|
73
|
-
return '';
|
|
74
|
-
}
|
|
75
|
-
try {
|
|
76
|
-
const payload = JSON.parse(data);
|
|
77
|
-
if (typeof payload === 'string') {
|
|
78
|
-
return payload;
|
|
79
|
-
}
|
|
80
|
-
if (!isRecord(payload)) {
|
|
81
|
-
return '';
|
|
82
|
-
}
|
|
83
|
-
const type = typeof payload.type === 'string' ? payload.type : undefined;
|
|
84
|
-
if (type && IGNORED_SSE_EVENT_TYPES.test(type)) {
|
|
85
|
-
return '';
|
|
86
|
-
}
|
|
87
|
-
const choiceDelta = getChoicesDelta(payload.choices);
|
|
88
|
-
if (choiceDelta) {
|
|
89
|
-
return choiceDelta;
|
|
90
|
-
}
|
|
91
|
-
for (const key of STREAM_TEXT_KEYS) {
|
|
92
|
-
const text = getStringValue(payload[key]);
|
|
93
|
-
if (text) {
|
|
94
|
-
return text;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return '';
|
|
98
|
-
}
|
|
99
|
-
catch {
|
|
100
|
-
return data;
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
export function parseStreamContent(text) {
|
|
104
|
-
const docsMatches = [...text.matchAll(/<docs>([\s\S]*?)<\/docs>/g)];
|
|
105
|
-
const docsReferences = docsMatches.length
|
|
106
|
-
? unicodeToString(docsMatches.at(-1)[1])
|
|
107
|
-
: '[]';
|
|
108
|
-
let refDocs = [];
|
|
109
|
-
try {
|
|
110
|
-
refDocs = JSON.parse(docsReferences).filter((r) => isObject(r));
|
|
111
|
-
}
|
|
112
|
-
catch {
|
|
113
|
-
//
|
|
114
|
-
}
|
|
115
|
-
const thinkMatches = [...text.matchAll(/<think>([\s\S]*?)<\/think>/g)];
|
|
116
|
-
let thinkingProcess = thinkMatches.at(-1)?.[1];
|
|
117
|
-
if (!thinkingProcess) {
|
|
118
|
-
const openThinkMatch = text.match(/<think>([\s\S]*)$/);
|
|
119
|
-
thinkingProcess = openThinkMatch?.[1];
|
|
120
|
-
}
|
|
121
|
-
const content = text
|
|
122
|
-
.replace(/<docs>[\s\S]*?<\/docs>/g, '')
|
|
123
|
-
.replace(/<think>[\s\S]*?<\/think>/g, '')
|
|
124
|
-
.replace(/<docs>[\s\S]*$/g, '')
|
|
125
|
-
.replace(/<think>[\s\S]*$/g, '');
|
|
126
|
-
return {
|
|
127
|
-
refDocs,
|
|
128
|
-
thinkingProcess: thinkingProcess && unicodeToString(thinkingProcess),
|
|
129
|
-
content: unicodeToString(content),
|
|
130
|
-
};
|
|
131
|
-
}
|