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
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 @@ -85,6 +85,9 @@
margin: 8px;
border-top: none;
}
&__img {
max-width: 100%;
}
> *:last-child {
margin-bottom: 0;
}
Expand Down
10 changes: 10 additions & 0 deletions src/chat/markdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { type ReactMarkdownOptions } from 'react-markdown/lib/react-markdown';
import classNames from 'classnames';
import remarkGfm from 'remark-gfm';

import Image from '../../image';
import CodeBlock, { type ICodeBlockProps } from '../codeBlock';
import './index.scss';

Expand Down Expand Up @@ -56,6 +57,15 @@ export default memo(
return <div>{data.children}</div>;
}
},
img({ src, ...rest }) {
return (
<Image
className="dtc__aigc__markdown__img"
src={src}
{...(rest as any)}
/>
);
},
...components,
}}
includeElementIndex
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