Skip to content
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

refactor: change AIMessageContent to ContentViewProvider #99

Merged
merged 1 commit into from
Dec 17, 2024
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/serious-chairs-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@difizen/magent-chat': patch
---

refactor: change MessageAddon & AIMessageContent to Providers
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import type {
BaseChatMessageModel,
} from '../../../chat-base/protocol.js';
import { AnswerState } from '../../../chat-base/protocol.js';
import { MesssageOpProvider } from '../../protocol.js';
import {
MesssageAddonViewProvider,
MesssageContentViewProvider,
MesssageOpProvider,
} from '../../protocol.js';
import type { ChatView } from '../../view.js';

interface AIMessageProps {
Expand Down Expand Up @@ -102,6 +106,9 @@ export const RecommendQuestions = (props: { message: BaseChatMessageModel }) =>
export const AIMessageContent = (props: AIMessageProps) => {
const item = useObserve(props.item);
const instance = useInject<ChatView>(ViewInstance);
const MesssageAddonView = useInject<MesssageAddonViewProvider>(
MesssageAddonViewProvider,
);
const Markdown = instance.Markdown;
const content: ReactNode = item.content;
if (!content) {
Expand Down Expand Up @@ -133,7 +140,7 @@ export const AIMessageContent = (props: AIMessageProps) => {
</span>
)}
</div>
<AIMessageAddon {...props} />
<MesssageAddonView {...props} />
</div>
);
} else {
Expand Down Expand Up @@ -169,7 +176,7 @@ export const AIMessageContent = (props: AIMessageProps) => {
className="chat-message-ai-fail"
/>
)}
<AIMessageAddon {...props} />
<MesssageAddonView {...props} />
</div>
);
}
Expand All @@ -181,6 +188,9 @@ export const AIMessage = (props: AIMessageProps) => {
const AvatarRender = instance.AvatarRender;

const MesssageOp = useInject<MesssageOpProvider>(MesssageOpProvider);
const MesssageContentView = useInject<MesssageContentViewProvider>(
MesssageContentViewProvider,
);

if (!conversation) {
return null;
Expand All @@ -192,7 +202,8 @@ export const AIMessage = (props: AIMessageProps) => {
<div className={classNames('chat-message-main', 'chat-message-main-ai')}>
<AvatarRender item={item} />
<div className={`chat-message-container`}>
<AIMessageContent {...props} />
{/* <AIMessageContent {...props} /> */}
<MesssageContentView {...props} />

<MesssageOp item={props.item} message={props.message} />

Expand Down
16 changes: 15 additions & 1 deletion web-packages/magent-chat/src/chat-view/module.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { ManaModule } from '@difizen/mana-app';

import { ChatMessageRender } from './chat-message-render.js';
import { AIMessageAddon, AIMessageContent } from './components/message/ai-message.js';
import { MessageOp } from './components/message/message-op.js';
import { DefaultChatMessageItemRenderContribution } from './default-chat-messsage-render-contribution.js';
import { ChatMessageItemRenderContribution, MesssageOpProvider } from './protocol.js';
import {
ChatMessageItemRenderContribution,
MesssageOpProvider,
MesssageContentViewProvider,
MesssageAddonViewProvider,
} from './protocol.js';
import { ChatView } from './view.js';

export const ChatViewModule = ManaModule.create('magent-chat-view')
Expand All @@ -12,6 +18,14 @@ export const ChatViewModule = ManaModule.create('magent-chat-view')
token: MesssageOpProvider,
useValue: MessageOp,
},
{
token: MesssageContentViewProvider,
useValue: AIMessageContent,
},
{
token: MesssageAddonViewProvider,
useValue: AIMessageAddon,
},
ChatView,
DefaultChatMessageItemRenderContribution,
ChatMessageRender,
Expand Down
14 changes: 14 additions & 0 deletions web-packages/magent-chat/src/chat-view/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,17 @@ export type MesssageOpProvider = FC<{
}>;

export const MesssageOpProvider = Symbol('MesssageOpProvider');

export type MesssageContentViewProvider = FC<{
message: BaseChatMessageModel;
item: BaseChatMessageItemModel;
}>;

export const MesssageContentViewProvider = Symbol('MesssageContentViewProvider');

export type MesssageAddonViewProvider = FC<{
message: BaseChatMessageModel;
item: BaseChatMessageItemModel;
}>;

export const MesssageAddonViewProvider = Symbol('MesssageAddonViewProvider');
Loading