(
chatKey: string,
messageId: string,
newContent: string,
options?: { overwriteSubsequent?: boolean }
)
| 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, |
nothing calls this directly
no test coverage detected