(chatKey: string, aiChatId: string)
| 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) |
nothing calls this directly
no test coverage detected