-
Notifications
You must be signed in to change notification settings - Fork 2
feat: migrate intelligence support #160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@alauda/doom": minor | ||
| --- | ||
|
|
||
| feat: migrate intelligence support |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
packages/doom/src/global/Intelligence/AIAssistant/Chat/ChatRefDocs/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import { clsx } from 'clsx' | ||
| import { useCallback, useMemo, useState } from 'react' | ||
|
|
||
| import { X } from '../../../../../runtime/components/_X.tsx' | ||
| import type { RefDoc } from '../../types.ts' | ||
|
|
||
| import AngleDownIcon from '@alauda/doom/assets/angle-down.svg?react' | ||
| import { useTranslation } from '@alauda/doom/runtime' | ||
| import classes from '@alauda/doom/styles/chat-ref-docs.module.scss' | ||
|
|
||
| export interface ChatRefDocsProps { | ||
| refDocs: RefDoc[] | ||
| } | ||
|
|
||
| export const ChatRefDocs = ({ refDocs }: ChatRefDocsProps) => { | ||
| const t = useTranslation() | ||
| const [expand, setExpand] = useState(false) | ||
| const toggleExpand = useCallback(() => { | ||
| setExpand((prev) => !prev) | ||
| }, []) | ||
| const displayedDocs = useMemo( | ||
| () => (expand ? refDocs : refDocs.slice(0, 3)), | ||
| [expand, refDocs], | ||
| ) | ||
| return ( | ||
| <div className={clsx('chat-ref-docs', classes.container)}> | ||
| <div className={classes.header}> | ||
| <span className={classes.title}> | ||
| {t('referenced_doc_links') + t('colon')} | ||
| </span> | ||
| {refDocs.length > 3 && ( | ||
| <span className={classes.action} onClick={toggleExpand}> | ||
| {t(expand ? 'view_less_related_docs' : 'view_more_related_docs')} ( | ||
| {refDocs.length}) | ||
| <AngleDownIcon | ||
| className={clsx(classes.icon, expand && classes.expanded)} | ||
| /> | ||
| </span> | ||
| )} | ||
| </div> | ||
| <ul className={classes.docs}> | ||
| {displayedDocs.map((doc) => ( | ||
| <li key={doc.id} className={classes.doc}> | ||
| <X.a | ||
| href={doc.path} | ||
| title={doc.content} | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| > | ||
| {doc.content} | ||
| </X.a> | ||
| </li> | ||
| ))} | ||
| </ul> | ||
| </div> | ||
| ) | ||
| } | ||
15 changes: 15 additions & 0 deletions
15
packages/doom/src/global/Intelligence/AIAssistant/Chat/ThinkingProcess/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import { Markdown, useTranslation } from '@alauda/doom/runtime' | ||
|
|
||
| export interface ThinkingProcessProps { | ||
| children: string | ||
| } | ||
|
|
||
| export const ThinkingProcess = ({ children }: ThinkingProcessProps) => { | ||
| const t = useTranslation() | ||
| return ( | ||
| <div> | ||
| <div>{t('thinking_process')}</div> | ||
| <Markdown>{children}</Markdown> | ||
| </div> | ||
| ) | ||
| } |
37 changes: 37 additions & 0 deletions
37
packages/doom/src/global/Intelligence/AIAssistant/Chat/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import { clsx } from 'clsx' | ||
| import type { Ref } from 'react' | ||
JounQin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| import type { ChatMessage } from '../types.js' | ||
|
|
||
| import { ChatRefDocs } from './ChatRefDocs/index.js' | ||
| import { ThinkingProcess } from './ThinkingProcess/index.js' | ||
|
|
||
| import AssistantIcon from '@alauda/doom/assets/assistant.svg?react' | ||
| import { Markdown } from '@alauda/doom/runtime' | ||
| import classes from '@alauda/doom/styles/chat.module.scss' | ||
|
|
||
| export interface ChatProps { | ||
| ref?: Ref<HTMLUListElement> | ||
| messages: ChatMessage[] | ||
| } | ||
|
|
||
| export const Chat = ({ ref, messages }: ChatProps) => ( | ||
| <ul ref={ref} className={classes.container}> | ||
| {messages.map(({ id, role, content, thinkingProcess, refDocs }) => ( | ||
| <li key={`${role}-${id}`} className={clsx(classes.chat, classes[role])}> | ||
| {role === 'assistant' && <AssistantIcon className={classes.icon} />} | ||
| <div className={classes.content}> | ||
| {thinkingProcess && ( | ||
| <ThinkingProcess>{thinkingProcess}</ThinkingProcess> | ||
| )} | ||
| {refDocs?.length ? <ChatRefDocs refDocs={refDocs} /> : null} | ||
| {typeof content === 'string' ? ( | ||
| <Markdown>{content}</Markdown> | ||
| ) : ( | ||
| content | ||
| )} | ||
| </div> | ||
| </li> | ||
| ))} | ||
| </ul> | ||
| ) | ||
40 changes: 40 additions & 0 deletions
40
packages/doom/src/global/Intelligence/AIAssistant/Preamble/ApiErrorAlert/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import { useMemo } from 'react' | ||
|
|
||
| import type { ApiError } from '../types.js' | ||
|
|
||
| import AlertIcon from '@alauda/doom/assets/alert.svg?react' | ||
| import { useTranslation } from '@alauda/doom/runtime' | ||
|
|
||
| export interface ApiErrorAlertProps { | ||
| error: ApiError | ||
| } | ||
|
|
||
| export const ApiErrorAlert = ({ error }: ApiErrorAlertProps) => { | ||
| const t = useTranslation() | ||
| const message = useMemo(() => { | ||
| // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition | ||
| if (!error.response) { | ||
| return t('ERR_INTERNET_DISCONNECTED') | ||
| } | ||
| const reason = error.data?.reason as | ||
| | 'AccountDisabledError' | ||
| | 'CaptchaError' | ||
| | 'LoginError' | ||
| | 'NetworkError' | ||
| | 'TenantError' | ||
| | 'TenantNotFoundError' | ||
| | undefined | ||
| const message = error.data?.message || error.message | ||
| try { | ||
| return reason ? t(reason) || reason : message | ||
| } catch { | ||
| return message | ||
| } | ||
| }, [error, t]) | ||
| return ( | ||
| <div className="api-error-alert"> | ||
| <AlertIcon className="api-error-alert__icon" /> | ||
| {message} | ||
| </div> | ||
| ) | ||
| } |
34 changes: 34 additions & 0 deletions
34
packages/doom/src/global/Intelligence/AIAssistant/Preamble/Button/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { clsx } from 'clsx' | ||
JounQin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| import type { ButtonHTMLAttributes } from 'react' | ||
|
|
||
| export interface ButtonProps | ||
| extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'type'> { | ||
| type?: 'primary' | ||
| htmlType?: 'submit' | 'reset' | 'button' | ||
| block?: boolean | ||
| loading?: boolean | ||
| } | ||
|
|
||
| export const Button = ({ | ||
| className, | ||
| block, | ||
| type, | ||
| htmlType = 'button', | ||
| loading, | ||
| disabled = loading, | ||
| ...props | ||
| }: ButtonProps) => { | ||
| return ( | ||
| <button | ||
| className={clsx( | ||
| 'button', | ||
| block && 'button--block', | ||
| type && `button--${type}`, | ||
| className, | ||
| )} | ||
| type={htmlType} | ||
| disabled={disabled} | ||
| {...props} | ||
JounQin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /> | ||
| ) | ||
| } | ||
52 changes: 52 additions & 0 deletions
52
packages/doom/src/global/Intelligence/AIAssistant/Preamble/CaptchaInput/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import { type ComponentType, useCallback, useMemo } from 'react' | ||
| import { normalizeUrl } from 'x-fetch' | ||
|
|
||
| import { FormItem } from '../FormItem/index.js' | ||
| import { Input, type InputProps } from '../Input/index.js' | ||
|
|
||
| import { useTranslation } from '@alauda/doom/runtime' | ||
|
|
||
| export interface CaptchaInputProps extends Omit<InputProps, 'type'> { | ||
| Component?: ComponentType<InputProps> | ||
| origin: string | ||
| captchaId: string | ||
| timestamp?: number | ||
| onTimestampChange: (timestamp: number) => void | ||
| } | ||
|
|
||
| export const CaptchaInput = ({ | ||
| Component = Input, | ||
| origin, | ||
| captchaId, | ||
| timestamp, | ||
| onTimestampChange, | ||
| ...props | ||
| }: CaptchaInputProps) => { | ||
| const t = useTranslation() | ||
|
|
||
| const captcha = useMemo( | ||
| () => normalizeUrl(`${origin}/api/v1/captcha`, { captchaId, timestamp }), | ||
| [origin, captchaId, timestamp], | ||
| ) | ||
|
|
||
| const onRefresh = useCallback(() => { | ||
| onTimestampChange(Date.now()) | ||
| }, [onTimestampChange]) | ||
|
|
||
| return ( | ||
| <div className="captcha-input"> | ||
| <FormItem | ||
| suffix={ | ||
| <img | ||
| className="captcha-input__captcha" | ||
| src={captcha} | ||
| onClick={onRefresh} | ||
| alt={t('captcha')} | ||
| /> | ||
| } | ||
| > | ||
| <Component name="captchaValue" {...props} /> | ||
| </FormItem> | ||
| </div> | ||
| ) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.