MCPcopy Index your code
hub / github.com/ChatLab/ChatLab / loadAIChat

Function loadAIChat

src/stores/aiChat.ts:529–557  ·  view source on GitHub ↗
(chatKey: string, aiChatId: string)

Source from the content-addressed store, hash-verified

527 }
528
529 async function loadAIChat(chatKey: string, aiChatId: string): Promise<boolean> {
530 const state = getSessionState(chatKey)
531 if (!state) return false
532
533 try {
534 const conversation = await useAIService().getAIChat(aiChatId)
535 const buffer = getOrCreateBuffer(state, aiChatId, conversation?.assistantId ?? null)
536
537 if (!buffer.loaded) {
538 const [history, tokenUsage] = await Promise.all([
539 useAIService().getMessages(aiChatId),
540 useAIService().getAIChatTokenUsage(aiChatId),
541 ])
542 buffer.messages.splice(0, buffer.messages.length, ...history.map((msg) => toRuntimeMessage(msg)))
543 buffer.sourceMessages.splice(0, buffer.sourceMessages.length)
544 buffer.currentKeywords.splice(0, buffer.currentKeywords.length)
545 buffer.sessionTokenUsage = toTokenUsage(tokenUsage)
546 buffer.loaded = true
547 }
548
549 buffer.assistantId = conversation?.assistantId ?? buffer.assistantId ?? null
550 bindDisplayedBuffer(state, aiChatId)
551 applySessionAssistantSelection(chatKey)
552 return true
553 } catch (error) {
554 console.error('[AI] 加载对话历史失败:', error)
555 return false
556 }
557 }
558
559 function focusAIChat(chatKey: string, aiChatId: string | null): boolean {
560 const state = getSessionState(chatKey)

Callers

nothing calls this directly

Calls 12

useAIServiceFunction · 0.90
getSessionStateFunction · 0.85
getOrCreateBufferFunction · 0.85
toRuntimeMessageFunction · 0.85
toTokenUsageFunction · 0.85
bindDisplayedBufferFunction · 0.85
getAIChatMethod · 0.65
allMethod · 0.65
getMessagesMethod · 0.65
getAIChatTokenUsageMethod · 0.65
errorMethod · 0.65

Tested by

no test coverage detected