(
chatKey: string,
state: AIChatSessionState,
targetBuffer: AIChatBuffer,
editIndex: number,
originalMessage: ChatMessage,
content: string
)
| 1494 | } |
| 1495 | |
| 1496 | async function editCurrentRoundOnly( |
| 1497 | chatKey: string, |
| 1498 | state: AIChatSessionState, |
| 1499 | targetBuffer: AIChatBuffer, |
| 1500 | editIndex: number, |
| 1501 | originalMessage: ChatMessage, |
| 1502 | content: string |
| 1503 | ): Promise<SendMessageResult> { |
| 1504 | const thisRequestId = generateId('req') |
| 1505 | let lastDoneUsage: TokenUsage | undefined |
| 1506 | let hasStreamError = false |
| 1507 | |
| 1508 | setActiveTaskMeta(chatKey, content, thisRequestId, state.currentAIChatId) |
| 1509 | applySessionAssistantSelection(chatKey) |
| 1510 | void ensureOwnerInfo(chatKey) |
| 1511 | |
| 1512 | state.isAIThinking = true |
| 1513 | state.isLoadingSource = true |
| 1514 | state.currentToolStatus = null |
| 1515 | state.toolsUsedInCurrentRound = [] |
| 1516 | state.agentStatus = null |
| 1517 | state.isAborted = false |
| 1518 | state.currentRequestId = thisRequestId |
| 1519 | state.currentAgentRequestId = '' |
| 1520 | |
| 1521 | const oldAiResponse = targetBuffer.messages[editIndex + 1] |
| 1522 | const hasOldAiResponse = oldAiResponse?.role === 'assistant' |
| 1523 | const subsequentMessages = hasOldAiResponse |
| 1524 | ? targetBuffer.messages.slice(editIndex + 2) |
| 1525 | : targetBuffer.messages.slice(editIndex + 1) |
| 1526 | |
| 1527 | const aiPlaceholder: ChatMessage = { |
| 1528 | id: generateId('ai'), |
| 1529 | role: 'assistant', |
| 1530 | content: '', |
| 1531 | timestamp: Date.now(), |
| 1532 | isStreaming: true, |
| 1533 | contentBlocks: [], |
| 1534 | } |
| 1535 | |
| 1536 | const currentSkillId = skillStore.activeSkillId |
| 1537 | const currentSkillName = skillStore.activeSkill?.name |
| 1538 | if (currentSkillId && currentSkillName) { |
| 1539 | aiPlaceholder.contentBlocks!.push({ type: 'skill', skillId: currentSkillId, skillName: currentSkillName }) |
| 1540 | } |
| 1541 | |
| 1542 | const editedUserMessage: ChatMessage = { |
| 1543 | ...originalMessage, |
| 1544 | content, |
| 1545 | } |
| 1546 | const removeCount = hasOldAiResponse ? 2 : 1 |
| 1547 | targetBuffer.messages.splice(editIndex, removeCount, editedUserMessage, aiPlaceholder) |
| 1548 | const aiMessageIndex = editIndex + 1 |
| 1549 | |
| 1550 | const restoreOriginal = () => { |
| 1551 | targetBuffer.messages.splice(editIndex, targetBuffer.messages.length - editIndex, originalMessage) |
| 1552 | if (hasOldAiResponse) { |
| 1553 | targetBuffer.messages.splice(editIndex + 1, 0, oldAiResponse) |
no test coverage detected