@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 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="16" height="14.859" viewBox="0 0 16 14.859"><g fill="none" fill-rule="evenodd"><path d="M0-1h16v16H0z" opacity=".1"/><path fill="currentColor" fill-rule="nonzero" d="M9.143 12.278V10.58a.29.29 0 0 0-.286-.295H7.143a.29.29 0 0 0-.286.295v1.697c0 .16.125.295.286.295h1.714a.29.29 0 0 0 .286-.295m-.018-3.34.16-4.098a.22.22 0 0 0-.088-.17c-.054-.044-.134-.098-.215-.098H7.018c-.08 0-.16.054-.214.098a.25.25 0 0 0-.09.188l.153 4.08c0 .117.134.206.303.206h1.652c.161 0 .295-.09.304-.205M9 .599l6.858 12.573a1.142 1.142 0 0 1-1 1.688H1.142c-.401 0-.776-.215-.982-.563a1.13 1.13 0 0 1-.018-1.125L7 .598a1.136 1.136 0 0 1 2 0"/></g></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 16 16"><defs><path id="a" d="M5.94 6.93 11.878.99l-.99-.99-4.95 4.95L.99 0 0 .99z"/></defs><g fill="none" fill-rule="evenodd" transform="translate(2.075 4.6)"><mask id="b" fill="#fff"><use xlink:href="#a"/></mask><use xlink:href="#a" fill="#323437"/><path fill="#007AF5" d="M-2.075-4.6h16v16h-16z" mask="url(#b)"/></g></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="20" viewBox="0 0 24 20"><defs><linearGradient id="a" x1="13.328%" x2="84.752%" y1="15.278%" y2="84.722%"><stop offset="0%" stop-color="#1245FF"/><stop offset="32.769%" stop-color="#2D87FF"/><stop offset="100%" stop-color="#8840FF"/></linearGradient></defs><g fill="none" fill-rule="evenodd"><rect width="3.023" height="6.335" x="14.253" y="6.273" fill="currentColor" rx="1.512"/><rect width="3.023" height="6.335" x="5.5" y="6.273" fill="currentColor" rx="1.512"/><path fill="url(#a)" fill-rule="nonzero" d="M19.441 0c2.476 0 4.49 1.941 4.534 4.353l.001.074L24 20h-7.358c-.835 0-1.512-.662-1.512-1.478 0-.8.649-1.45 1.46-1.478h4.382l-.02-12.612c0-.798-.65-1.448-1.459-1.475H4.535c-.817 0-1.483.634-1.51 1.427l-.002.05v8.056c0 2.12 1.64 3.891 3.788 4.11l.074.007 4.317.364c.832.07 1.448.786 1.376 1.6-.07.796-.774 1.39-1.584 1.349l-.052-.004-4.317-.364C2.915 19.239.058 16.23.001 12.6L0 12.49V4.435C0 2.01 1.99.04 4.46 0h.074z"/></g></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="icon" viewBox="0 0 1024 1024"><path d="M870.4 243.2 598.208 512 870.4 780.8l-81.664 80.64-272.192-268.8-281.28 277.76-81.664-80.64L434.88 512 153.6 234.24l81.664-80.64L516.48 431.36l272.192-268.8z"/></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"><path fill="currentColor" d="M1.737 15.5A.744.744 0 0 1 1 14.75V1.25c0-.414.33-.75.737-.75h10.316a.73.73 0 0 1 .52.22c.139.14.216.331.216.53V3.5h-1.473V2H2.474v12h8.842v-1.5h1.473v2.25c0 .199-.077.39-.215.53a.73.73 0 0 1-.521.22zm9.579-4.5V8.75H6.158v-1.5h5.158V5L15 8z"/></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="20" height="20" viewBox="0 0 20 20"><defs><path id="a" d="m5.925 0-.001 4.574 4.576.001v1.35l-4.576-.001.001 4.576h-1.35l-.001-4.576L0 5.925v-1.35l4.574-.001L4.575 0z"/></defs><g fill="none" fill-rule="evenodd"><path fill="#007AF5" fill-rule="nonzero" d="M10 0c5.523 0 10 4.477 10 10s-4.477 10-10 10H0V10C0 4.477 4.477 0 10 0"/><g transform="translate(4.75 4.75)"><mask id="b" fill="#fff"><use xlink:href="#a"/></mask><use xlink:href="#a" fill="#323437"/><path fill="#FFF" d="M-.75-.75h12v12h-12z" mask="url(#b)"/></g></g></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 16 16"><defs><path id="a" d="M8 0a8 8 0 1 1 0 16A8 8 0 0 1 8 0m0 1.2a6.8 6.8 0 1 0 0 13.6A6.8 6.8 0 0 0 8 1.2m0 9.7a1 1 0 1 1 0 2 1 1 0 0 1 0-2m0-8a2.9 2.9 0 0 1 2.9 2.9c0 .906-.578 1.716-1.641 2.453A1.3 1.3 0 0 0 8.7 9.286v.814H7.3v-.778a2.7 2.7 0 0 1 1.16-2.219C9.186 6.601 9.5 6.16 9.5 5.8a1.5 1.5 0 0 0-3-.031V5.8H5.1A2.9 2.9 0 0 1 8 2.9"/></defs><g fill="currentColor" fill-rule="evenodd"><mask id="b" fill="#fff"><use xlink:href="#a"/></mask><use xlink:href="#a" fill="currentColor" fill-rule="nonzero"/><path fill="currentColor" d="M0 0h16v16H0z" mask="url(#b)"/></g></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"><path fill="currentColor" fill-rule="evenodd" d="M14.488.053.825 4.256c-.951.292-1.124 1.563-.286 2.1l4.037 2.58c.431.275.99.238 1.382-.092l5.038-4.251c.273-.23.642.138.412.411l-4.252 5.04c-.33.39-.367.95-.091 1.38l2.58 4.037c.536.838 1.807.665 2.1-.285l4.202-13.664A1.167 1.167 0 0 0 14.488.053"/></svg>
@@ -218,6 +218,10 @@ const getCommonConfig = async ({ config, root, configFilePath, base, version, do
218
218
  },
219
219
  server: {
220
220
  open,
221
+ proxy: {
222
+ '/api/v1': 'https://cloud.alauda.cn',
223
+ '/smart/api': 'https://docs-dev.alauda.cn',
224
+ },
221
225
  },
222
226
  tools: {
223
227
  rspack(rspackConfig, { mergeConfig, rspack }) {
@@ -0,0 +1,5 @@
1
+ import type { RefDoc } from '../../types.ts';
2
+ export interface ChatRefDocsProps {
3
+ refDocs: RefDoc[];
4
+ }
5
+ export declare const ChatRefDocs: ({ refDocs }: ChatRefDocsProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,16 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { clsx } from 'clsx';
3
+ import { useCallback, useMemo, useState } from 'react';
4
+ import { X } from "../../../../../runtime/components/_X.js";
5
+ import AngleDownIcon from '@alauda/doom/assets/angle-down.svg?react';
6
+ import { useTranslation } from '@alauda/doom/runtime';
7
+ import classes from '@alauda/doom/styles/chat-ref-docs.module.scss';
8
+ export const ChatRefDocs = ({ refDocs }) => {
9
+ const t = useTranslation();
10
+ const [expand, setExpand] = useState(false);
11
+ const toggleExpand = useCallback(() => {
12
+ setExpand((prev) => !prev);
13
+ }, []);
14
+ const displayedDocs = useMemo(() => (expand ? refDocs : refDocs.slice(0, 3)), [expand, refDocs]);
15
+ return (_jsxs("div", { className: clsx('chat-ref-docs', classes.container), children: [_jsxs("div", { className: classes.header, children: [_jsx("span", { className: classes.title, children: t('referenced_doc_links') + t('colon') }), refDocs.length > 3 && (_jsxs("span", { className: classes.action, onClick: toggleExpand, children: [t(expand ? 'view_less_related_docs' : 'view_more_related_docs'), " (", refDocs.length, ")", _jsx(AngleDownIcon, { className: clsx(classes.icon, expand && classes.expanded) })] }))] }), _jsx("ul", { className: classes.docs, children: displayedDocs.map((doc) => (_jsx("li", { className: classes.doc, children: _jsx(X.a, { href: doc.path, title: doc.content, target: "_blank", rel: "noopener noreferrer", children: doc.content }) }, doc.id))) })] }));
16
+ };
@@ -0,0 +1,4 @@
1
+ export interface ThinkingProcessProps {
2
+ children: string;
3
+ }
4
+ export declare const ThinkingProcess: ({ children }: ThinkingProcessProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,6 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Markdown, useTranslation } from '@alauda/doom/runtime';
3
+ export const ThinkingProcess = ({ children }) => {
4
+ const t = useTranslation();
5
+ return (_jsxs("div", { children: [_jsx("div", { children: t('thinking_process') }), _jsx(Markdown, { children: children })] }));
6
+ };
@@ -0,0 +1,7 @@
1
+ import type { Ref } from 'react';
2
+ import type { ChatMessage } from '../types.js';
3
+ export interface ChatProps {
4
+ ref?: Ref<HTMLUListElement>;
5
+ messages: ChatMessage[];
6
+ }
7
+ export declare const Chat: ({ ref, messages }: ChatProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,8 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { clsx } from 'clsx';
3
+ import { ChatRefDocs } from './ChatRefDocs/index.js';
4
+ import { ThinkingProcess } from './ThinkingProcess/index.js';
5
+ import AssistantIcon from '@alauda/doom/assets/assistant.svg?react';
6
+ import { Markdown } from '@alauda/doom/runtime';
7
+ import classes from '@alauda/doom/styles/chat.module.scss';
8
+ export const Chat = ({ ref, messages }) => (_jsx("ul", { ref: ref, className: classes.container, children: messages.map(({ id, role, content, thinkingProcess, refDocs }) => (_jsxs("li", { className: clsx(classes.chat, classes[role]), children: [role === 'assistant' && _jsx(AssistantIcon, { className: classes.icon }), _jsxs("div", { className: classes.content, children: [thinkingProcess && (_jsx(ThinkingProcess, { children: thinkingProcess })), refDocs?.length ? _jsx(ChatRefDocs, { refDocs: refDocs }) : null, typeof content === 'string' ? (_jsx(Markdown, { children: content })) : (content)] })] }, `${role}-${id}`))) }));
@@ -0,0 +1,5 @@
1
+ import type { ApiError } from '../types.js';
2
+ export interface ApiErrorAlertProps {
3
+ error: ApiError;
4
+ }
5
+ export declare const ApiErrorAlert: ({ error }: ApiErrorAlertProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,22 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useMemo } from 'react';
3
+ import AlertIcon from '@alauda/doom/assets/alert.svg?react';
4
+ import { useTranslation } from '@alauda/doom/runtime';
5
+ export const ApiErrorAlert = ({ error }) => {
6
+ const t = useTranslation();
7
+ const message = useMemo(() => {
8
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
9
+ if (!error.response) {
10
+ return t('ERR_INTERNET_DISCONNECTED');
11
+ }
12
+ const reason = error.data?.reason;
13
+ const message = error.data?.message || error.message;
14
+ try {
15
+ return reason ? t(reason) || reason : message;
16
+ }
17
+ catch {
18
+ return message;
19
+ }
20
+ }, [error, t]);
21
+ return (_jsxs("div", { className: "api-error-alert", children: [_jsx(AlertIcon, { className: "api-error-alert__icon" }), message] }));
22
+ };
@@ -0,0 +1,8 @@
1
+ import type { ButtonHTMLAttributes } from 'react';
2
+ export interface ButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'type'> {
3
+ type?: 'primary';
4
+ htmlType?: 'submit' | 'reset' | 'button';
5
+ block?: boolean;
6
+ loading?: boolean;
7
+ }
8
+ export declare const Button: ({ className, block, type, htmlType, loading, disabled, ...props }: ButtonProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,5 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { clsx } from 'clsx';
3
+ export const Button = ({ className, block, type, htmlType = 'button', loading, disabled = loading, ...props }) => {
4
+ return (_jsx("button", { className: clsx('button', block && 'button--block', type && `button--${type}`, className), type: htmlType, disabled: disabled, ...props }));
5
+ };
@@ -0,0 +1,10 @@
1
+ import { type ComponentType } from 'react';
2
+ import { type InputProps } from '../Input/index.js';
3
+ export interface CaptchaInputProps extends Omit<InputProps, 'type'> {
4
+ Component?: ComponentType<InputProps>;
5
+ origin: string;
6
+ captchaId: string;
7
+ timestamp?: number;
8
+ onTimestampChange: (timestamp: number) => void;
9
+ }
10
+ export declare const CaptchaInput: ({ Component, origin, captchaId, timestamp, onTimestampChange, ...props }: CaptchaInputProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,14 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useCallback, useMemo } from 'react';
3
+ import { normalizeUrl } from 'x-fetch';
4
+ import { FormItem } from '../FormItem/index.js';
5
+ import { Input } from '../Input/index.js';
6
+ import { useTranslation } from '@alauda/doom/runtime';
7
+ export const CaptchaInput = ({ Component = Input, origin, captchaId, timestamp, onTimestampChange, ...props }) => {
8
+ const t = useTranslation();
9
+ const captcha = useMemo(() => normalizeUrl(`${origin}/api/v1/captcha`, { captchaId, timestamp }), [origin, captchaId, timestamp]);
10
+ const onRefresh = useCallback(() => {
11
+ onTimestampChange(Date.now());
12
+ }, [onTimestampChange]);
13
+ return (_jsx("div", { className: "captcha-input", children: _jsx(FormItem, { suffix: _jsx("img", { className: "captcha-input__captcha", src: captcha, onClick: onRefresh, alt: t('captcha') }), children: _jsx(Component, { name: "captchaValue", ...props }) }) }));
14
+ };
@@ -0,0 +1,6 @@
1
+ import { type ComponentType } from 'react';
2
+ import { type InputProps } from '../Input/index.js';
3
+ export interface FocusInputProps extends InputProps {
4
+ Component?: ComponentType<InputProps>;
5
+ }
6
+ export declare const FocusInput: ({ Component, className, style, placeholder, value, onFocus, onBlur, ...props }: FocusInputProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,19 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { clsx } from 'clsx';
3
+ import { useCallback, useState } from 'react';
4
+ import { Input } from '../Input/index.js';
5
+ export const FocusInput = ({ Component = Input, className, style, placeholder, value, onFocus, onBlur, ...props }) => {
6
+ const [active, setActive] = useState(!!value);
7
+ const [focus, setFocus] = useState(false);
8
+ const handleFocus = useCallback((ev) => {
9
+ setActive(true);
10
+ setFocus(true);
11
+ onFocus?.(ev);
12
+ }, [onFocus]);
13
+ const handleBlur = useCallback((ev) => {
14
+ setActive(!!ev.target.value);
15
+ setFocus(false);
16
+ onBlur?.(ev);
17
+ }, [onBlur]);
18
+ return (_jsxs("div", { className: clsx('focus-input', { 'focus-input--active': active, 'focus-input--focus': focus }, className), style: style, children: [_jsx(Component, { onFocus: handleFocus, onBlur: handleBlur, ...props }), _jsx("span", { className: "focus-input__placeholder", children: placeholder })] }));
19
+ };
@@ -0,0 +1,16 @@
1
+ import { type ChangeEvent, type ReactElement, type ReactNode } from 'react';
2
+ export interface FormItemProps<T> {
3
+ label?: string;
4
+ children: ReactElement<{
5
+ defaultValue?: T;
6
+ value?: T;
7
+ onChange?: (ev: ChangeEvent<{
8
+ value: T;
9
+ }>) => void;
10
+ required?: boolean;
11
+ }>;
12
+ required?: boolean;
13
+ prefix?: ReactNode;
14
+ suffix?: ReactNode;
15
+ }
16
+ export declare const FormItem: <T>({ label, children, required, prefix, suffix, }: FormItemProps<T>) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,27 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { clsx } from 'clsx';
3
+ import { cloneElement, useCallback, useState, } from 'react';
4
+ import { useTranslation } from '@alauda/doom/runtime';
5
+ export const FormItem = ({ label, children, required, prefix, suffix, }) => {
6
+ const t = useTranslation();
7
+ const { defaultValue, value, onChange: childOnChange, required: childRequired, } = children.props;
8
+ const [innerValue, setInnerValue] = useState(value ?? defaultValue);
9
+ if (value != null && value !== innerValue) {
10
+ setInnerValue(value);
11
+ }
12
+ const [dirty, setDirty] = useState(false);
13
+ const onChange = useCallback((ev) => {
14
+ setDirty(true);
15
+ childOnChange?.(ev);
16
+ setInnerValue(ev.target.value);
17
+ }, [childOnChange]);
18
+ required = childRequired ?? required;
19
+ const error = dirty && required && !innerValue;
20
+ return (_jsxs(_Fragment, { children: [_jsxs("div", { className: clsx('form-item', error && 'form-item--error'), children: [!!prefix && _jsx("span", { className: "form-item__prefix", children: prefix }),
21
+ /* eslint-disable-next-line @eslint-react/no-clone-element */
22
+ cloneElement(children, {
23
+ value: innerValue,
24
+ onChange,
25
+ required,
26
+ }), !!suffix && _jsx("span", { className: "form-item__suffix", children: suffix })] }), error && (_jsxs("div", { className: "form-item__error", children: [label || t('current_field'), t('field_required')] }))] }));
27
+ };
@@ -0,0 +1,7 @@
1
+ import type { InputHTMLAttributes, Ref } from 'react';
2
+ export interface InputProps extends InputHTMLAttributes<HTMLInputElement> {
3
+ ref?: Ref<HTMLInputElement>;
4
+ prefix?: string;
5
+ suffix?: string;
6
+ }
7
+ export declare const Input: ({ ref, className, prefix, suffix, ...props }: InputProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,5 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { clsx } from 'clsx';
3
+ export const Input = ({ ref, className, prefix, suffix, ...props }) => {
4
+ return (_jsxs("div", { className: "input__container", children: [prefix && _jsx("span", { className: "input__prefix", children: prefix }), _jsx("input", { ref: ref, className: clsx('input', className), ...props }), suffix && _jsx("span", { className: "input__suffix", children: suffix })] }));
5
+ };
@@ -0,0 +1,3 @@
1
+ import { type FormHTMLAttributes } from 'react';
2
+ export type LoginFormProps = FormHTMLAttributes<HTMLFormElement>;
3
+ export declare const LoginForm: ({ onSubmit, ...props }: LoginFormProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,88 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { useRef, useState, } from 'react';
3
+ import { Tooltip } from 'react-tooltip';
4
+ import { ApiMethod, ResponseError, xfetch } from 'x-fetch';
5
+ import { CLOUD_AUTH_ORIGIN_KEY, CLOUD_AUTH_ORIGIN_VALUES, CLOUD_AUTH_ORIGINS, } from "../../../constants.js";
6
+ import { useCloudAuth } from "../../../context.js";
7
+ import { ApiErrorAlert } from "../ApiErrorAlert/index.js";
8
+ import { Button } from "../Button/index.js";
9
+ import { CaptchaInput } from "../CaptchaInput/index.js";
10
+ import { FocusInput } from "../FocusInput/index.js";
11
+ import { FormItem } from "../FormItem/index.js";
12
+ import { Radio, RadioGroup } from "../Radio/index.js";
13
+ import { cryptoPassword } from "./utils.js";
14
+ import QuestionCycleIcon from '@alauda/doom/assets/question-circle.svg?react';
15
+ import { useMemoizedFn, useTranslation } from '@alauda/doom/runtime';
16
+ const isLoginError = (err) => err instanceof ResponseError;
17
+ export const LoginForm = ({ onSubmit, ...props }) => {
18
+ const t = useTranslation();
19
+ const [origin, setOrigin] = useState(() => {
20
+ let origin = localStorage.getItem(CLOUD_AUTH_ORIGIN_KEY);
21
+ if (origin == null || !CLOUD_AUTH_ORIGIN_VALUES.includes(origin)) {
22
+ origin = CLOUD_AUTH_ORIGIN_VALUES[0];
23
+ localStorage.setItem(CLOUD_AUTH_ORIGIN_KEY, origin);
24
+ }
25
+ return origin;
26
+ });
27
+ const [loading, setLoading] = useState();
28
+ const [error, setError] = useState();
29
+ const pwdPubkeyRef = useRef(null);
30
+ const onRegionChange = useMemoizedFn((ev) => {
31
+ const origin = ev.target.value;
32
+ setOrigin(origin);
33
+ setError(undefined);
34
+ pwdPubkeyRef.current = null;
35
+ localStorage.setItem(CLOUD_AUTH_ORIGIN_KEY, origin);
36
+ });
37
+ const { setAuthBasic } = useCloudAuth();
38
+ const captchaId = error?.data?.extra?.captchaId;
39
+ const [timestamp, setTimestamp] = useState();
40
+ const handleSubmit = useMemoizedFn(async (ev) => {
41
+ ev.preventDefault();
42
+ ev.stopPropagation();
43
+ onSubmit?.(ev);
44
+ const formData = new FormData(ev.currentTarget);
45
+ const origin = formData.get('origin');
46
+ formData.delete('origin');
47
+ setLoading(true);
48
+ if (pwdPubkeyRef.current == null) {
49
+ try {
50
+ pwdPubkeyRef.current = await xfetch(`${origin}/api/v1/pubkey`);
51
+ }
52
+ catch (err) {
53
+ setError(err);
54
+ setLoading(false);
55
+ return;
56
+ }
57
+ }
58
+ formData.set('password', cryptoPassword(pwdPubkeyRef.current, formData.get('password')));
59
+ if (captchaId) {
60
+ formData.set('captchaId', captchaId);
61
+ }
62
+ try {
63
+ const { accessToken } = await xfetch(`${origin}/api/v1/login`, {
64
+ method: ApiMethod.POST,
65
+ body: formData,
66
+ });
67
+ setAuthBasic({
68
+ origin,
69
+ token: accessToken,
70
+ });
71
+ }
72
+ catch (err) {
73
+ if (!isLoginError(err)) {
74
+ throw err;
75
+ }
76
+ if (err.data?.reason === 'PubkeyExpireError') {
77
+ pwdPubkeyRef.current = null;
78
+ await handleSubmit(ev);
79
+ return;
80
+ }
81
+ setError(err);
82
+ }
83
+ finally {
84
+ setLoading(false);
85
+ }
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') }) })] }));
88
+ };
@@ -0,0 +1,18 @@
1
+ import type { ApiError } from '../types.js';
2
+ export interface PasswordPubKey {
3
+ ts: string;
4
+ pubkey: string;
5
+ }
6
+ export interface LoginResponse {
7
+ accessToken: string;
8
+ expiresIn: string;
9
+ refreshToken?: string;
10
+ refreshExpiresIn?: string;
11
+ }
12
+ export type LoginErrorReason = 'CaptchaError' | 'LoginError' | 'NetworkError' | 'PubkeyExpireError' | 'TenantError' | 'TenantNotFoundError';
13
+ export interface LoginErrorExtra {
14
+ captchaId?: string;
15
+ action?: 'UPDATE_PASSWORD';
16
+ code: string;
17
+ }
18
+ export type LoginError<T extends LoginErrorReason = LoginErrorReason> = ApiError<T, LoginErrorExtra>;
@@ -0,0 +1,3 @@
1
+ import type { PasswordPubKey } from './types.js';
2
+ export declare const crypto: (pubkey: string, encryptString: string) => string;
3
+ export declare const cryptoPassword: ({ pubkey, ts }: PasswordPubKey, password: string) => string;
@@ -0,0 +1,7 @@
1
+ import { JSEncrypt } from 'jsencrypt';
2
+ export const crypto = (pubkey, encryptString) => {
3
+ const encrypt = new JSEncrypt();
4
+ encrypt.setPublicKey(pubkey);
5
+ return encrypt.encrypt(encryptString);
6
+ };
7
+ export const cryptoPassword = ({ pubkey, ts }, password) => crypto(pubkey, JSON.stringify({ ts, password }));
@@ -0,0 +1,7 @@
1
+ import { type ChangeEvent } from 'react';
2
+ export interface RadioProps {
3
+ label: string;
4
+ value: string | number;
5
+ onChange?: (ev: ChangeEvent<HTMLInputElement>) => void;
6
+ }
7
+ export declare const Radio: ({ label, value, onChange }: RadioProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,11 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useCallback, use } from 'react';
3
+ import { RadioGroupContext } from "./context.js";
4
+ export const Radio = ({ label, value, onChange }) => {
5
+ const { name, value: groupValue, onChange: onGroupChange, } = use(RadioGroupContext);
6
+ const handleChange = useCallback((ev) => {
7
+ onChange?.(ev);
8
+ onGroupChange?.(ev);
9
+ }, [onChange, onGroupChange]);
10
+ return (_jsxs("label", { className: "radio", children: [_jsx("input", { name: name, type: "radio", value: value, onChange: handleChange, checked: value === groupValue }), _jsx("span", { className: "radio__label", children: label })] }));
11
+ };
@@ -0,0 +1,11 @@
1
+ import { type ChangeEvent, type ReactNode } from 'react';
2
+ export interface RadioGroupProps {
3
+ id?: string;
4
+ name?: string;
5
+ value?: string;
6
+ onChange?: (value: ChangeEvent<HTMLInputElement>) => void;
7
+ children?: ReactNode;
8
+ prefix?: ReactNode;
9
+ suffix?: ReactNode;
10
+ }
11
+ export declare const RadioGroup: ({ id: id_, name, value, onChange, children, prefix, suffix, }: RadioGroupProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,21 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useCallback, useId, useMemo, useState, } from 'react';
3
+ import { RadioGroupContext } from "./context.js";
4
+ export const RadioGroup = ({ id: id_, name, value, onChange, children, prefix, suffix, }) => {
5
+ const innerId = useId();
6
+ const id = id_ || innerId;
7
+ name ??= id;
8
+ const [innerValue, setInnerValue] = useState(value ?? '');
9
+ if (value != null && innerValue !== value) {
10
+ setInnerValue(value);
11
+ }
12
+ const handleChange = useCallback((ev) => {
13
+ onChange?.(ev);
14
+ setInnerValue(ev.target.value);
15
+ }, [onChange]);
16
+ return (_jsx("div", { id: id, className: "radio-group", children: _jsxs(RadioGroupContext, { value: useMemo(() => ({
17
+ name,
18
+ value: innerValue,
19
+ onChange: handleChange,
20
+ }), [name, innerValue, handleChange]), children: [!!prefix && _jsx("span", { className: "radio-group__prefix", children: prefix }), children, !!suffix && _jsx("span", { className: "radio-group__suffix", children: suffix })] }) }));
21
+ };
@@ -0,0 +1,7 @@
1
+ import { type ChangeEvent } from 'react';
2
+ export interface RadioGroupContext<T = unknown> {
3
+ name: string;
4
+ value: T;
5
+ onChange?: (value: ChangeEvent<HTMLInputElement>) => void;
6
+ }
7
+ export declare const RadioGroupContext: import("react").Context<RadioGroupContext<unknown>>;
@@ -0,0 +1,2 @@
1
+ import { createContext } from 'react';
2
+ export const RadioGroupContext = createContext(null);
@@ -0,0 +1,2 @@
1
+ export * from './Radio.tsx';
2
+ export * from './RadioGroup.tsx';
@@ -0,0 +1,2 @@
1
+ export * from "./Radio.js";
2
+ export * from "./RadioGroup.js";
@@ -0,0 +1,4 @@
1
+ export interface PreambleProps {
2
+ loggedIn: boolean;
3
+ }
4
+ export declare const Preamble: ({ loggedIn }: PreambleProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,10 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { clsx } from 'clsx';
3
+ import { LoginForm } from "./LoginForm/index.js";
4
+ import AssistantIcon from '@alauda/doom/assets/assistant.svg?react';
5
+ import { useTranslation } from '@alauda/doom/runtime';
6
+ import classes from '@alauda/doom/styles/preamble.module.scss';
7
+ export const Preamble = ({ loggedIn }) => {
8
+ const t = useTranslation();
9
+ return (_jsxs("div", { className: clsx(classes.preamble, loggedIn && classes.loggedIn), children: [_jsx(AssistantIcon, { width: 48, height: 40 }), _jsx("div", { className: classes.title, children: t(loggedIn ? 'hi_there' : 'user_login') }), _jsx("div", { className: classes.content, children: t(loggedIn ? 'ai_assistant_tip' : 'user_login_tip') }), loggedIn || _jsx(LoginForm, { className: classes.form })] }));
10
+ };
@@ -0,0 +1,9 @@
1
+ import type { ResponseError } from 'x-fetch';
2
+ export interface ApiErrorOptions<R extends string = string, E extends object = object, T = unknown> {
3
+ code: number;
4
+ reason: R;
5
+ message: string;
6
+ extra?: E;
7
+ details?: T[];
8
+ }
9
+ export type ApiError<T extends string = string, E extends object = object> = ResponseError<ApiErrorOptions<T, E>>;
@@ -0,0 +1,8 @@
1
+ export interface ResizableUserInputProps {
2
+ placeholder?: string;
3
+ value?: string;
4
+ loading?: boolean;
5
+ onChange?: (value: string) => void;
6
+ onSend?: (value: string) => void;
7
+ }
8
+ export declare const ResizableUserInput: ({ value, loading, onChange, onSend, }: ResizableUserInputProps) => import("react/jsx-runtime").JSX.Element;
@@ -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;