Skip to content

Commit

Permalink
fix(ui): chat content do not change when agent changed
Browse files Browse the repository at this point in the history
  • Loading branch information
BroKun committed Aug 7, 2024
1 parent e545032 commit 67dd424
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion web/platform/src/modules/chat/components/input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export const Input = forwardRef<TextAreaRef, InputProps>(function Input(
ref={ref}
value={value}
placeholder={'输入聊天内容'}
bordered={false}
variant="borderless"
autoSize={{ minRows: 1 }}
style={{ resize: 'none', padding: '0px 16px', maxHeight: 80 }}
onChange={onInputChange}
Expand Down
5 changes: 5 additions & 0 deletions web/ui/src/modules/base-layout/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ body {
}
}

&-header {
z-index: 3;
}

&-container {
height: calc(100% - 61px);
z-index: 2;
}
}
2 changes: 1 addition & 1 deletion web/ui/src/modules/chat-message/chat-message-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class ChatMessageModel implements Disposable {
};

updateMeta = (option: MessageOption) => {
this.id = option.id;
this.id = option.id || dayjs().unix();
this.agentId = option.agentId;
this.sessionId = option.sessionId;
if (option.messages && option.messages.length > 0) {
Expand Down
2 changes: 1 addition & 1 deletion web/ui/src/modules/chat-message/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const toMessageOption = (msg: APIMessage, agentId: string): MessageOption
items = JSON.parse(msg.content);
}
return {
id: msg.message_id,
id: msg.message_id || msg.id,
sessionId: msg.session_id,
agentId,
messages: items.map(toMessageItem),
Expand Down
10 changes: 6 additions & 4 deletions web/ui/src/views/agent-dev/chat-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ const AgentChatComponent = forwardRef<HTMLDivElement>(
instance.agentId = agentId;

useEffect(() => {
if (instance.sessions?.active) {
instance.openChat(instance.sessions?.active);
}
instance.openChat(instance.sessions?.active);
}, [instance, instance.sessions?.active]);

return (
Expand Down Expand Up @@ -112,7 +110,11 @@ export class AgentView extends BaseView {
this.initSessionView();
}

openChat = async (session: SessionModel) => {
openChat = async (session?: SessionModel) => {
if (!session) {
this.chat = undefined;
return;
}
const chatView = await this.viewManager.getOrCreateView(ChatView, {
agentId: session.agentId,
sessionId: session.id,
Expand Down
2 changes: 1 addition & 1 deletion web/ui/src/views/chat/components/input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export const Input = forwardRef<TextAreaRef, InputProps>(function Input(
ref={ref}
value={value}
placeholder={'输入聊天内容'}
bordered={false}
variant="borderless"
autoSize={{ minRows: 1 }}
style={{ resize: 'none', padding: '0px 16px', maxHeight: 80 }}
onChange={onInputChange}
Expand Down
2 changes: 1 addition & 1 deletion web/ui/src/views/chat/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
height: 100%;
display: flex;
flex-direction: column;
background-color: var(--mana-input-background);
background-color: var(--mana-color-bg-container);
box-sizing: border-box;

&-content {
Expand Down
4 changes: 2 additions & 2 deletions web/ui/src/views/chat/view.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ClearOutlined, VerticalAlignBottomOutlined } from '@ant-design/icons';
import { VerticalAlignBottomOutlined } from '@ant-design/icons';
import {
BaseView,
Deferred,
Expand All @@ -11,7 +11,7 @@ import {
ViewOption,
} from '@difizen/mana-app';
import { useInject } from '@difizen/mana-app';
import { Button, FloatButton } from 'antd';
import { FloatButton } from 'antd';
import classnames from 'classnames';
import type { RefObject } from 'react';
import { useEffect, useRef } from 'react';
Expand Down
3 changes: 2 additions & 1 deletion web/ui/src/views/sessions/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export class SessionsView extends BaseView {
agentId: string;

option: SessionsViewOption;

constructor(@inject(ViewOption) option: SessionsViewOption) {
super();
this.option = option;
Expand Down Expand Up @@ -92,7 +93,7 @@ export class SessionsView extends BaseView {

protected disposeSession = (session: SessionModel) => {
const sessions = this.sessions.filter((i) => i.id !== session.id);
if (this.active.id === session.id) {
if (this.active?.id === session.id) {
if (sessions.length > 0) {
this.active = sessions[0];
} else {
Expand Down

0 comments on commit 67dd424

Please sign in to comment.