Skip to content

feat: optimize AIAgent components #561

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 8 additions & 8 deletions src/chat/__tests__/useChat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,21 +138,21 @@ describe('Test useChat', () => {
act(() => {
result.current.message.update(mockPrompt.id, mockMessage.id, (m) => ({
...m,
assistantId: 111,
assistantId: '111',
}));
});
expect(result.current.message.get(mockPrompt.id, mockMessage.id)).toEqual<BaseMessage>(
new BaseMessage({ ...mockMessage, assistantId: 111 })
new BaseMessage({ ...mockMessage, assistantId: '111' })
);

fn.mockRestore();
act(() => {
result.current.message.update(mockPrompt.id, mockMessage.id, {
assistantId: 123,
assistantId: '123',
});
});
expect(result.current.message.get(mockPrompt.id, mockMessage.id)).toEqual<BaseMessage>(
new BaseMessage({ ...mockMessage, assistantId: 123 })
new BaseMessage({ ...mockMessage, assistantId: '123' })
);
expect(fn).toBeCalledTimes(1);

Expand All @@ -162,13 +162,13 @@ describe('Test useChat', () => {
mockMessage.id,
(m) => ({
...m,
assistantId: 111,
assistantId: '111',
}),
false
);
});
expect(result.current.message.get(mockPrompt.id, mockMessage.id)).toEqual<BaseMessage>(
new BaseMessage({ ...mockMessage, assistantId: 111 })
new BaseMessage({ ...mockMessage, assistantId: '111' })
);
expect(fn).toBeCalledTimes(1);

Expand Down Expand Up @@ -418,7 +418,7 @@ describe('Test useChat', () => {
act(() => {
result.current.message.create(mockPrompt.id, mockMessage);
result.current.message.update(mockPrompt.id, mockMessage.id, {
assistantId: 1,
assistantId: '1',
});
result.current.message.remove(mockPrompt.id, mockMessage.id);
});
Expand All @@ -428,7 +428,7 @@ describe('Test useChat', () => {
result.current.conversation.create(mockConversation);
result.current.prompt.update(mockPrompt.id, { assistantId: 'assistant_prompt_id' });
result.current.message.create(mockPrompt.id, mockMessage);
result.current.message.update(mockPrompt.id, mockMessage.id, { assistantId: 1 });
result.current.message.update(mockPrompt.id, mockMessage.id, { assistantId: '1' });
result.current.message.remove(mockPrompt.id, mockMessage.id);
});
expect(result.error).toBeUndefined();
Expand Down
7 changes: 4 additions & 3 deletions src/chat/codeBlock/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import { Prism as SyntaxHighlighter, SyntaxHighlighterProps } from 'react-syntax
import { oneLight } from 'react-syntax-highlighter/dist/cjs/styles/prism';
import classNames from 'classnames';

import Copy, { type ICopyProps } from '../../copy';
import Copy from '../../copy';
import { CopyIcon } from '../icon';
import { CopyOptions } from '../useContext';
import './index.scss';

export interface ICodeBlockProps {
copy?: boolean | ICopyProps;
copy?: boolean | CopyOptions;
className?: string;
style?: React.CSSProperties;
convert?: boolean;
Expand All @@ -34,7 +35,7 @@ export default function CodeBlock({
return { value, language };
}, [children]);

const copy = useMemo<{ disabled: boolean; options: Partial<ICopyProps> }>(() => {
const copy = useMemo<{ disabled: boolean; options: CopyOptions }>(() => {
if (typeof rawCopy === 'boolean') {
return {
disabled: !rawCopy,
Expand Down
4 changes: 2 additions & 2 deletions src/chat/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export type PromptProperties = {

export type MessageProperties = {
id: Id;
assistantId?: number;
assistantId?: string;
creator?: string;
createdAt?: Timestamp;
content?: string;
Expand Down Expand Up @@ -100,7 +100,7 @@ export abstract class Prompt {
export abstract class Message {
id: Id;
// 后端 Id
assistantId?: number;
assistantId?: string;
creator?: string;
createdAt: Timestamp;
content: string;
Expand Down
3 changes: 3 additions & 0 deletions src/chat/markdown/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,7 @@
}
}
}
img {
max-width: 100%;
}
}
4 changes: 4 additions & 0 deletions src/chat/markdown/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { memo, type PropsWithChildren, useEffect } from 'react';
import ReactMarkdown from 'react-markdown';
import { type ReactMarkdownOptions } from 'react-markdown/lib/react-markdown';
import { Image } from 'antd';
import classNames from 'classnames';
import remarkGfm from 'remark-gfm';

Expand Down Expand Up @@ -48,6 +49,9 @@ export default memo(
hr() {
return <hr color="#ebecf0" className="dtc__aigc__markdown__hr" />;
},
img({ src, ...rest }) {
return <Image src={src} {...(rest as any)} />;
},
...components,
}}
{...rest}
Expand Down
1 change: 1 addition & 0 deletions src/chat/pagination/index.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.dtc-aigc-pagination {
user-select: none;
display: flex;
align-items: center;
gap: 4px;
Expand Down
1 change: 1 addition & 0 deletions src/chat/welcome/index.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
$primaryGradient: #00BAC6 0%, #0067FF 50%, #450FDE 100%;

.dtc__welcome {
border-radius: 8px;
overflow: hidden;
color: #FFF;
background: linear-gradient(110deg, $primaryGradient) border-box;
Expand Down
Loading