665
*/
666
private _ensureDefaultChat(sessionKey: string, summary: SessionSummary, turns?: Turn[], draft?: Message, defaultChatTitle?: string): void {
668
>
// Empty title means "inherit the session title"; a persisted independent
669
>
// rename (`defaultChatTitle`) is seeded back here so it survives restore.
670
>
const chatSummary: ChatSummary = { ...createDefaultChatSummary(summary, chatUri), title: defaultChatTitle ?? '' };
671
>
this._chatStates.set(chatUri, { ...createChatState(chatSummary), turns: turns ?? [], draft });
672
>
const entry = this._sessionStates.get(sessionKey);
673
>
if (entry) {
674
>
// Update the session's chat catalog in place so the object
675
>
// identity returned by `createSession`/`restoreSession` stays
676
>
// live in the map. Callers (e.g. `AgentService.createSession`)
677
>
// mutate the returned state directly (`state.config = …`), so
678
>
// replacing the map entry with a fresh clone here would strand
679
>
// those mutations on a detached object.
680
>
entry.state.chats = [chatSummary];
681
>
entry.state.defaultChat = chatUri;
682
>
}
683
>
}
684
685
/**