Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/shaggy-garlics-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@alauda/doom": minor
---

feat: migrate intelligence support
2 changes: 1 addition & 1 deletion .github/workflows/pkg-pr-new.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ jobs:
run: yarn build

- name: Publish
run: yarn dlx pkg-pr-new publish './packages/*' --packageManager=yarn # --compact
run: yarn dlx pkg-pr-new publish './packages/*' --packageManager=yarn --compact
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"packageManager": "yarn@4.9.4",
"scripts": {
"build": "tsc -b",
"build": "yarn clean && tsc -b",
"clean": "tsc -b --clean",
"dev": "yarn swc-node --watch-path packages/doom/src/cli --watch-path packages/doom/src/plugins packages/doom/src/cli/index.ts",
"docs": "run-s docs:build docs:export",
Expand All @@ -21,9 +21,7 @@
"doom": "yarn swc-node packages/doom/src/cli/index.ts",
"fixture": "yarn dev fixture-docs",
"format": "prettier --write .",
"lint": "run-p 'lint:*'",
"lint:es": "eslint .",
"lint:tsc": "tsc -b",
"lint": "eslint .",
"prepare": "simple-git-hooks && patch-package && yarn-berry-deduplicate || exit 0",
"release": "yarn build && changeset publish",
"serve": "yarn doom serve",
Expand Down
1 change: 1 addition & 0 deletions packages/doom/assets/alert.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/doom/assets/angle-down.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/doom/assets/assistant.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/doom/assets/close.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/doom/assets/logout.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/doom/assets/new-chat.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/doom/assets/question-circle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/doom/assets/send.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 9 additions & 4 deletions packages/doom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
},
"bin": "lib/cli/index.js",
"exports": {
"./assets/*": "./assets/*",
"./config": "./lib/config.js",
"./cspell": "./lib/cspell.js",
"./eslint": "./lib/eslint.js",
"./runtime": "./lib/runtime/index.js",
"./styles/*": "./styles/*",
"./theme": "./lib/theme.js",
"./types": "./lib/types.js",
"./package.json": "./package.json"
Expand All @@ -45,16 +47,17 @@
"@openapi-contrib/openapi-schema-to-json-schema": "^5.1.0",
"@playwright/browser-chromium": "^1.55.0",
"@rsbuild/plugin-react": "^1.3.5",
"@rsbuild/plugin-sass": "^1.3.5",
"@rsbuild/plugin-sass": "^1.4.0",
"@rsbuild/plugin-svgr": "^1.2.2",
"@rsbuild/plugin-yaml": "^1.0.3",
"@rspress/core": "2.0.0-beta.28",
"@rspress/plugin-algolia": "2.0.0-beta.28",
"@rspress/plugin-llms": "2.0.0-beta.28",
"@rspress/plugin-sitemap": "2.0.0-beta.28",
"@rspress/shared": "2.0.0-beta.28",
"@shikijs/transformers": "^3.11.0",
"@shikijs/transformers": "^3.12.0",
"@total-typescript/ts-reset": "^0.6.1",
"ab64": "^0.1.6",
"chokidar": "^4.0.3",
"clsx": "^2.1.1",
"commander": "^13.1.0 || ^14.0.0",
Expand All @@ -64,19 +67,21 @@
"eslint-plugin-mdx": "^3.6.2",
"globals": "^16.3.0",
"html-tag-names": "^2.1.0",
"jsencrypt": "^3.5.4",
"md-attr-parser": "^1.3.0",
"mdast-util-mdx": "^3.0.0",
"mdast-util-mdx-jsx": "^3.2.0",
"mdast-util-phrasing": "^4.1.0",
"mdast-util-to-markdown": "^2.1.2",
"mdast-util-to-string": "^4.0.0",
"mermaid": "^11.10.1",
"openai": "^5.15.0",
"openai": "^5.16.0",
"openapi-types": "^12.1.3",
"p-ratelimit": "^1.0.1",
"picomatch": "^4.0.3",
"pluralize": "^8.0.0",
"react-markdown": "^10.1.0",
"react-tooltip": "^5.29.1",
"rehype-raw": "^7.0.0",
"rehype-sanitize": "^6.0.0",
"remark-directive": "^4.0.0",
Expand All @@ -91,7 +96,7 @@
"remark-mdx": "^3.1.0",
"remark-message-control": "^8.0.0",
"remark-stringify": "^11.0.0",
"shiki": "^3.11.0",
"shiki": "^3.12.0",
"simple-git": "^3.28.0",
"string-width": "^7.2.0",
"swagger2openapi": "^7.0.8",
Expand Down
4 changes: 4 additions & 0 deletions packages/doom/src/cli/load-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,10 @@ const getCommonConfig = async ({
},
server: {
open,
proxy: {
'/api/v1': 'https://cloud.alauda.cn',
'/smart/api': 'https://docs-dev.alauda.cn',
},
},
tools: {
rspack(rspackConfig, { mergeConfig, rspack }) {
Expand Down
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>
)
}
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 packages/doom/src/global/Intelligence/AIAssistant/Chat/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { clsx } from 'clsx'
import type { Ref } from 'react'

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>
)
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>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { clsx } from 'clsx'
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}
/>
)
}
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>
)
}
Loading
Loading