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

Function editMessageAndRegenerate

src/stores/aiChat.ts:1436–1465  ·  view source on GitHub ↗
(
    chatKey: string,
    messageId: string,
    newContent: string,
    options?: { overwriteSubsequent?: boolean }
  )

Source from the content-addressed store, hash-verified

1434 }
1435
1436 async function editMessageAndRegenerate(
1437 chatKey: string,
1438 messageId: string,
1439 newContent: string,
1440 options?: { overwriteSubsequent?: boolean }
1441 ): Promise<SendMessageResult> {
1442 const state = getSessionState(chatKey)
1443 const content = newContent.trim()
1444 if (!state || !state.currentAIChatId) return { success: false, reason: 'error' }
1445 if (!content) return { success: false, reason: 'empty' }
1446 if (state.isAIThinking || activeTask.value) {
1447 return { success: false, reason: 'busy', activeTask: activeTask.value }
1448 }
1449
1450 const overwriteAll = options?.overwriteSubsequent ?? false
1451 const targetBuffer = getOrCreateBuffer(state, state.currentAIChatId, state.selectedAssistantId)
1452 const editIndex = targetBuffer.messages.findIndex((message) => message.id === messageId)
1453 const originalMessage = targetBuffer.messages[editIndex]
1454 if (!originalMessage || originalMessage.role !== 'user' || originalMessage.isStreaming) {
1455 return { success: false, reason: 'error' }
1456 }
1457 if (originalMessage.content.trim() === content) {
1458 return { success: false, reason: 'empty' }
1459 }
1460
1461 if (overwriteAll) {
1462 return editAndOverwriteAll(chatKey, state, targetBuffer, editIndex, originalMessage, content)
1463 }
1464 return editCurrentRoundOnly(chatKey, state, targetBuffer, editIndex, originalMessage, content)
1465 }
1466
1467 async function editAndOverwriteAll(
1468 chatKey: string,

Callers

nothing calls this directly

Calls 4

getSessionStateFunction · 0.85
getOrCreateBufferFunction · 0.85
editAndOverwriteAllFunction · 0.85
editCurrentRoundOnlyFunction · 0.85

Tested by

no test coverage detected