fix(core): chat history not show in independent page (#13069)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **New Features**
* Added the ability to reload the current AI chat session, clearing and
reinitializing the chat context.
* Introduced a function to close the chat history menu in the AI chat
toolbar.
* Enabled seamless opening of specific chat sessions from the chat
toolbar, with improved loading state handling and error feedback.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Cats Juice
2025-07-07 20:32:13 +08:00
committed by GitHub
parent ce679af7df
commit f8be0cc465
3 changed files with 42 additions and 1 deletions

View File

@@ -308,6 +308,11 @@ export class AIChatContent extends SignalWatcher(
this.closePreviewPanel(true);
}
public reloadSession() {
this.reset();
this.initChatContent().catch(console.error);
}
public openPreviewPanel(content?: TemplateResult<1>) {
this.showPreviewPanel = true;
if (content) this.previewPanelContent = content;

View File

@@ -186,4 +186,8 @@ export class AIChatToolbar extends WithDisposable(ShadowlessElement) {
closeOnClickAway: true,
});
};
public closeHistoryMenu() {
this.abortController?.abort();
}
}

View File

@@ -59,6 +59,7 @@ export const Component = () => {
null
);
const [isTogglingPin, setIsTogglingPin] = useState(false);
const [isOpeningSession, setIsOpeningSession] = useState(false);
const chatContainerRef = useRef<HTMLDivElement>(null);
const chatToolContainerRef = useRef<HTMLDivElement>(null);
const widthSignalRef = useRef<Signal<number>>(signal(0));
@@ -109,6 +110,25 @@ export const Component = () => {
}
}, [client, createSession, currentSession, isTogglingPin, workspaceId]);
const onOpenSession = useCallback(
(sessionId: string) => {
if (isOpeningSession) return;
setIsOpeningSession(true);
client
.getSession(workspaceId, sessionId)
.then(session => {
setCurrentSession(session);
chatContent?.reloadSession();
chatTool?.closeHistoryMenu();
})
.catch(console.error)
.finally(() => {
setIsOpeningSession(false);
});
},
[chatContent, chatTool, client, isOpeningSession, workspaceId]
);
// create a temp doc/host for ai-chat-content
useEffect(() => {
let tempDoc: Doc | null = null;
@@ -187,6 +207,9 @@ export const Component = () => {
}
tool.session = currentSession;
tool.workspaceId = workspaceId;
tool.docDisplayConfig = docDisplayConfig;
tool.onOpenSession = onOpenSession;
tool.onNewSession = () => {
if (!currentSession) return;
@@ -204,7 +227,16 @@ export const Component = () => {
chatToolContainerRef.current.append(tool);
setChatTool(tool);
}
}, [chatContent, chatTool, currentSession, isHeaderProvided, togglePin]);
}, [
chatContent,
chatTool,
currentSession,
docDisplayConfig,
isHeaderProvided,
onOpenSession,
togglePin,
workspaceId,
]);
const onChatContainerRef = useCallback((node: HTMLDivElement) => {
if (node) {