(
parsed: Extract<ParsedCommand, { type: "compact" }>,
context: CommandHandlerContext
)
| 1748 | * Handle /compact command execution |
| 1749 | */ |
| 1750 | export async function handleCompactCommand( |
| 1751 | parsed: Extract<ParsedCommand, { type: "compact" }>, |
| 1752 | context: CommandHandlerContext |
| 1753 | ): Promise<CommandHandlerResult> { |
| 1754 | const { |
| 1755 | api, |
| 1756 | workspaceId, |
| 1757 | sendMessageOptions, |
| 1758 | editMessageId, |
| 1759 | setInput, |
| 1760 | setAttachments, |
| 1761 | setSendingState, |
| 1762 | setToast, |
| 1763 | onCancelEdit, |
| 1764 | } = context; |
| 1765 | |
| 1766 | // normalizeModelInput handles null/empty — returns { model: null } for empty input |
| 1767 | const normalizedModel = normalizeModelInput(parsed.model); |
| 1768 | |
| 1769 | // Validate model format early - fail fast before sending to backend |
| 1770 | if (parsed.model && !normalizedModel.model) { |
| 1771 | setToast(createInvalidCompactModelToast(parsed.model)); |
| 1772 | return { clearInput: false, toastShown: true }; |
| 1773 | } |
| 1774 | |
| 1775 | setInput(""); |
| 1776 | setAttachments([]); |
| 1777 | setSendingState(true); |
| 1778 | |
| 1779 | try { |
| 1780 | // Build followUpContent directly from parsed command + context. |
| 1781 | const stagedAttachments = context.attachments ? getStagedAttachments(context.attachments) : []; |
| 1782 | const hasContent = |
| 1783 | parsed.continueMessage ?? |
| 1784 | context.fileParts?.length ?? |
| 1785 | context.reviews?.length ?? |
| 1786 | stagedAttachments.length; |
| 1787 | const followUpContent: CompactionFollowUpInput | undefined = hasContent |
| 1788 | ? { |
| 1789 | text: appendStagedAttachmentNotice(parsed.continueMessage ?? "", stagedAttachments), |
| 1790 | fileParts: context.fileParts, |
| 1791 | reviews: context.reviews, |
| 1792 | } |
| 1793 | : undefined; |
| 1794 | |
| 1795 | const resolvedModel = normalizedModel.model ?? undefined; |
| 1796 | |
| 1797 | const result = await executeCompaction({ |
| 1798 | api, |
| 1799 | workspaceId, |
| 1800 | maxOutputTokens: parsed.maxOutputTokens, |
| 1801 | followUpContent, |
| 1802 | model: resolvedModel, |
| 1803 | sendMessageOptions, |
| 1804 | editMessageId, |
| 1805 | }); |
| 1806 | |
| 1807 | if (!result.success) { |
no test coverage detected