@alauda/doom 1.12.4 → 1.12.6

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.
@@ -10,14 +10,14 @@ import { logger } from '@rspress/core';
10
10
  import { pluginAlgolia } from '@rspress/plugin-algolia';
11
11
  import { pluginLlms } from '@rspress/plugin-llms';
12
12
  import { pluginSitemap } from '@rspress/plugin-sitemap';
13
- import { addLeadingSlash, addTrailingSlash, normalizeSlash, removeLeadingSlash, } from '@rspress/shared';
13
+ import { addLeadingSlash, addTrailingSlash, removeLeadingSlash, } from '@rspress/shared';
14
14
  import { transformerMetaHighlight, transformerMetaWordHighlight, transformerNotationDiff, transformerNotationErrorLevel, transformerNotationFocus, transformerNotationHighlight, transformerNotationWordHighlight, transformerRemoveNotationEscape, } from '@shikijs/transformers';
15
15
  import { difference } from 'es-toolkit';
16
16
  import { glob } from 'tinyglobby';
17
17
  import { cyan } from 'yoctocolors';
18
18
  import { attributesPlugin } from '../plugins/attributes/index.js';
19
19
  import { apiPlugin, autoSidebarPlugin, autoTocPlugin, createTransformerCallouts, directivesPlugin, globalPlugin, mermaidPlugin, permissionPlugin, replacePlugin, } from '../plugins/index.js';
20
- import { isExplicitlyUnversioned, UNVERSIONED, } from '../shared/index.js';
20
+ import { isExplicitlyUnversioned, normalizeSlash, UNVERSIONED, } from '../shared/index.js';
21
21
  import { pathExists, pkgResolve, resolveStaticConfig } from '../utils/index.js';
22
22
  import { DEFAULT_CONFIG_NAME, DEFAULT_EXTENSIONS, I18N_FILE, SITES_FILE, YAML_EXTENSIONS, } from './constants.js';
23
23
  import { defaultGitHubUrl, isDoc } from './helpers.js';
@@ -233,7 +233,6 @@ const getCommonConfig = async ({ config, root, configFilePath, base, version, do
233
233
  server: {
234
234
  open,
235
235
  proxy: {
236
- '/api/v1': 'https://cloud.alauda.cn',
237
236
  '/smart/api': 'https://docs-dev.alauda.cn',
238
237
  },
239
238
  },
package/lib/eslint.js CHANGED
@@ -4,6 +4,7 @@ import cspellRecommended from '@cspell/eslint-plugin/recommended';
4
4
  import js from '@eslint/js';
5
5
  import react from '@eslint-react/eslint-plugin';
6
6
  import { merge } from 'es-toolkit/compat';
7
+ import { defineConfig } from 'eslint/config';
7
8
  import * as mdx from 'eslint-plugin-mdx';
8
9
  import globals from 'globals';
9
10
  import tseslint from 'typescript-eslint';
@@ -27,7 +28,7 @@ async function doom(cspellOptionsOrRoot) {
27
28
  cspellOptions = cspellOptionsOrRoot;
28
29
  }
29
30
  const cspellEnabled = cspellOptions !== null;
30
- return tseslint.config([
31
+ return defineConfig([
31
32
  {
32
33
  ignores: ['**/.yarn', '**/dist', '**/lib', '**/node_modules'],
33
34
  },
@@ -84,5 +84,5 @@ export const LoginForm = ({ onSubmit, ...props }) => {
84
84
  setLoading(false);
85
85
  }
86
86
  });
87
- return (_jsxs("form", { onSubmit: handleSubmit, ...props, children: [_jsx(FormItem, { children: _jsx(RadioGroup, { name: "origin", value: origin, onChange: onRegionChange, suffix: _jsxs(_Fragment, { children: [_jsx(QuestionCycleIcon, { className: "region-tip" }), _jsxs(Tooltip, { anchorSelect: ".region-tip", place: "top-start", children: [_jsx("div", { children: t('user_login_region_china_tip') }), _jsx("div", { children: t('user_login_region_global_tip') })] })] }), children: CLOUD_AUTH_ORIGINS.map(({ name, value }) => (_jsx(Radio, { label: name === 'local' ? 'Local' : t(`customer_portal_${name}`), value: value }, name))) }) }), error && _jsx(ApiErrorAlert, { error: error }), _jsx(FormItem, { label: t('account_id'), required: true, children: _jsx(FocusInput, { name: "tenant", placeholder: t('account_id') }) }), _jsx(FormItem, { label: t('username'), required: true, children: _jsx(FocusInput, { name: "username", placeholder: t('username') }) }), _jsx(FormItem, { label: t('password'), required: true, children: _jsx(FocusInput, { name: "password", type: "password", placeholder: t('password') }) }), captchaId && (_jsx(FormItem, { label: t('captcha'), required: true, children: _jsx(CaptchaInput, { Component: FocusInput, placeholder: t('captcha'), origin: origin, captchaId: captchaId, timestamp: timestamp, onTimestampChange: setTimestamp }) })), _jsx(FormItem, { children: _jsx(Button, { type: "primary", htmlType: "submit", block: true, loading: loading, children: t('login') }) })] }));
87
+ return (_jsxs("form", { onSubmit: handleSubmit, ...props, children: [_jsx(FormItem, { children: _jsx(RadioGroup, { name: "origin", value: origin, onChange: onRegionChange, suffix: _jsxs(_Fragment, { children: [_jsx(QuestionCycleIcon, { className: "region-tip" }), _jsxs(Tooltip, { anchorSelect: ".region-tip", place: "top-start", children: [_jsx("div", { children: t('user_login_region_china_tip') }), _jsx("div", { children: t('user_login_region_global_tip') })] })] }), children: CLOUD_AUTH_ORIGINS.map(({ name, value }) => (_jsx(Radio, { label: t(`customer_portal_${name}`), value: value }, name))) }) }), error && _jsx(ApiErrorAlert, { error: error }), _jsx(FormItem, { label: t('account_id'), required: true, children: _jsx(FocusInput, { name: "tenant", placeholder: t('account_id') }) }), _jsx(FormItem, { label: t('username'), required: true, children: _jsx(FocusInput, { name: "username", placeholder: t('username') }) }), _jsx(FormItem, { label: t('password'), required: true, children: _jsx(FocusInput, { name: "password", type: "password", placeholder: t('password') }) }), captchaId && (_jsx(FormItem, { label: t('captcha'), required: true, children: _jsx(CaptchaInput, { Component: FocusInput, placeholder: t('captcha'), origin: origin, captchaId: captchaId, timestamp: timestamp, onTimestampChange: setTimestamp }) })), _jsx(FormItem, { children: _jsx(Button, { type: "primary", htmlType: "submit", block: true, loading: loading, children: t('login') }) })] }));
88
88
  };
@@ -1,8 +1,8 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { clsx } from 'clsx';
3
- import { useRef, useState } from 'react';
3
+ import { useEffect, useRef, useState } from 'react';
4
4
  import { Tooltip } from 'react-tooltip';
5
- import { ApiMethod, xfetch } from 'x-fetch';
5
+ import { ApiMethod, interceptors, ResponseError, xfetch, } from 'x-fetch';
6
6
  import { useCloudAuth } from "../context.js";
7
7
  import { Chat } from "./Chat/index.js";
8
8
  import { Preamble } from "./Preamble/index.js";
@@ -31,6 +31,34 @@ export const AIAssistant = ({ open, onOpenChange }) => {
31
31
  setAuthBasic();
32
32
  onNewChat();
33
33
  });
34
+ useEffect(() => {
35
+ const interceptor = async (req, next) => {
36
+ if (!req.url.startsWith('/smart/')) {
37
+ return next(req);
38
+ }
39
+ if (!req.headers.has('Authorization')) {
40
+ req.headers.set('Authorization', `Bearer ${authInfo.token}`);
41
+ }
42
+ if (!req.headers.has('CLOUD_AUTH_ORIGIN')) {
43
+ req.headers.set('CLOUD_AUTH_ORIGIN', authInfo.origin);
44
+ }
45
+ try {
46
+ return await next(req);
47
+ }
48
+ catch (err) {
49
+ if (err instanceof ResponseError &&
50
+ // type-coverage:ignore-next-line -- no idea
51
+ err.response.status === 401) {
52
+ onLogout();
53
+ }
54
+ throw err;
55
+ }
56
+ };
57
+ interceptors.use(interceptor);
58
+ return () => {
59
+ interceptors.eject(interceptor);
60
+ };
61
+ }, [authInfo, onLogout]);
34
62
  const onClose = useMemoizedFn(() => {
35
63
  onOpenChange(false);
36
64
  });
@@ -60,7 +88,6 @@ export const AIAssistant = ({ open, onOpenChange }) => {
60
88
  if (!sessionIdRef.current) {
61
89
  const { session_id } = await xfetch('/smart/api/new_session', {
62
90
  method: ApiMethod.POST,
63
- headers: { username: authInfo.detail.user.name },
64
91
  });
65
92
  sessionIdRef.current = session_id;
66
93
  }
@@ -105,6 +132,9 @@ export const AIAssistant = ({ open, onOpenChange }) => {
105
132
  await onSend_(content);
106
133
  }
107
134
  catch {
135
+ if (!sessionIdRef.current) {
136
+ return;
137
+ }
108
138
  flushMessages((messages) => {
109
139
  const index = assistantMessageIndexRef.current;
110
140
  return [
@@ -1,4 +1,3 @@
1
- import { isProduction } from '@rspress/shared';
2
1
  export const CLOUD_AUTH_ORIGIN_KEY = '__CLOUD_AUTH_ORIGIN__';
3
2
  export const CLOUD_AUTH_TOKEN_KEY = '__CLOUD_AUTH_TOKEN__';
4
3
  const CLOUD_AUTH_ORIGINS = [
@@ -11,11 +10,5 @@ const CLOUD_AUTH_ORIGINS = [
11
10
  value: 'https://cloud.alauda.cn',
12
11
  },
13
12
  ];
14
- if (!isProduction()) {
15
- CLOUD_AUTH_ORIGINS.unshift({
16
- name: 'local',
17
- value: '',
18
- });
19
- }
20
13
  export const CLOUD_AUTH_ORIGIN_VALUES = CLOUD_AUTH_ORIGINS.map(({ value }) => value);
21
14
  export { CLOUD_AUTH_ORIGINS };
@@ -2,6 +2,7 @@ import { type ReactNode } from 'react';
2
2
  import type { AuthInfo } from './types.js';
3
3
  export interface CloudAuth {
4
4
  origin: string;
5
+ token?: string;
5
6
  detail?: AuthInfo;
6
7
  }
7
8
  export interface CloudAuthContext {
@@ -13,7 +13,7 @@ const getCloudAuth = () => {
13
13
  if (token == null) {
14
14
  return { origin };
15
15
  }
16
- return { origin, detail: getAuthInfoFromToken(token) };
16
+ return { origin, token, detail: getAuthInfoFromToken(token) };
17
17
  };
18
18
  export const CloudAuthProvider = ({ children }) => {
19
19
  const [authInfo, setAuthInfo] = useState(getCloudAuth);
@@ -27,6 +27,6 @@ export interface AuthInfo {
27
27
  user: AuthUser;
28
28
  }
29
29
  export interface CloudAuthRegion {
30
- name: 'global' | 'china' | 'local';
30
+ name: 'global' | 'china';
31
31
  value: string;
32
32
  }
@@ -9,5 +9,6 @@ export declare const getUnversionedVersion: (version?: string) => string | undef
9
9
  * hello world {#custom-id} -> { text: 'hello world', id: 'custom-id' }
10
10
  */
11
11
  export declare const extractTextAndId: (title: string) => string[];
12
+ export declare const normalizeSlash: (url: string) => string;
12
13
  export declare const withoutBase: (path: string, base: string) => string;
13
14
  export declare const matchNavbar: (item: NavItemWithLink, currentPathname: string, base: string) => boolean;
@@ -1,4 +1,4 @@
1
- import { addLeadingSlash, normalizeSlash } from '@rspress/shared';
1
+ import { addLeadingSlash, normalizePosixPath, removeTrailingSlash, } from '@rspress/shared';
2
2
  import { UNVERSIONED, UNVERSIONED_PREFIX } from "./constants.js";
3
3
  export const removeBothEndsSlashes = (str) => str?.replace(/^\/|\/$/g, '') || '';
4
4
  export const getPdfName = (lang, userBase, title) => `${removeBothEndsSlashes(userBase) || title || 'exported'}-${lang}.pdf`;
@@ -24,5 +24,6 @@ export const extractTextAndId = (title) => {
24
24
  customId,
25
25
  ];
26
26
  };
27
+ export const normalizeSlash = (url) => removeTrailingSlash(addLeadingSlash(normalizePosixPath(url)));
27
28
  export const withoutBase = (path, base) => addLeadingSlash(path).replace(normalizeSlash(base), '');
28
29
  export const matchNavbar = (item, currentPathname, base) => new RegExp(item.activeMatch || item.link).test(withoutBase(currentPathname, base));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alauda/doom",
3
- "version": "1.12.4",
3
+ "version": "1.12.6",
4
4
  "type": "module",
5
5
  "description": "Doctor Doom making docs.",
6
6
  "repository": {
@@ -41,7 +41,7 @@
41
41
  ],
42
42
  "dependencies": {
43
43
  "@alauda/doom-export": "^0.1.0",
44
- "@cspell/eslint-plugin": "^8.19.4 || ^9.2.0",
44
+ "@cspell/eslint-plugin": "^8.19.4 || ^9.2.1",
45
45
  "@eslint-react/eslint-plugin": "^1.52.9",
46
46
  "@inquirer/prompts": "^7.8.4",
47
47
  "@openapi-contrib/openapi-schema-to-json-schema": "^5.1.0",
@@ -50,12 +50,12 @@
50
50
  "@rsbuild/plugin-sass": "^1.4.0",
51
51
  "@rsbuild/plugin-svgr": "^1.2.2",
52
52
  "@rsbuild/plugin-yaml": "^1.0.3",
53
- "@rspress/core": "2.0.0-beta.29",
54
- "@rspress/plugin-algolia": "2.0.0-beta.29",
55
- "@rspress/plugin-llms": "2.0.0-beta.29",
56
- "@rspress/plugin-sitemap": "2.0.0-beta.29",
57
- "@rspress/shared": "2.0.0-beta.29",
58
- "@shikijs/transformers": "^3.12.1",
53
+ "@rspress/core": "2.0.0-beta.30",
54
+ "@rspress/plugin-algolia": "2.0.0-beta.30",
55
+ "@rspress/plugin-llms": "2.0.0-beta.30",
56
+ "@rspress/plugin-sitemap": "2.0.0-beta.30",
57
+ "@rspress/shared": "2.0.0-beta.30",
58
+ "@shikijs/transformers": "^3.12.2",
59
59
  "@total-typescript/ts-reset": "^0.6.1",
60
60
  "ab64": "^0.1.6",
61
61
  "chokidar": "^4.0.3",
@@ -75,7 +75,7 @@
75
75
  "mdast-util-to-markdown": "^2.1.2",
76
76
  "mdast-util-to-string": "^4.0.0",
77
77
  "mermaid": "^11.10.1",
78
- "openai": "^5.16.0",
78
+ "openai": "~5.17.0",
79
79
  "openapi-types": "^12.1.3",
80
80
  "p-ratelimit": "^1.0.1",
81
81
  "picomatch": "^4.0.3",
@@ -96,14 +96,14 @@
96
96
  "remark-mdx": "^3.1.1",
97
97
  "remark-message-control": "^8.0.0",
98
98
  "remark-stringify": "^11.0.0",
99
- "shiki": "^3.12.1",
99
+ "shiki": "^3.12.2",
100
100
  "simple-git": "^3.28.0",
101
101
  "string-width": "^7.2.0",
102
102
  "swagger2openapi": "^7.0.8",
103
103
  "tinyglobby": "^0.2.14",
104
104
  "type-fest": "^4.41.0",
105
105
  "typescript": "^5.9.2",
106
- "typescript-eslint": "^8.41.0",
106
+ "typescript-eslint": "^8.42.0",
107
107
  "unified": "^11.0.5",
108
108
  "unified-lint-rule": "^3.0.1",
109
109
  "unist-util-position": "^5.0.0",