mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
Fix compact command validation flow (#28)
* feat: Implement /compact command with processing feedback - Add 'compact' status type to session status store - Update SessionStatusIndicator to show purple pulsing animation for compaction - Add summarizeSession() API method to OpenCode client - Modify command handler for /compact to: - Get current model from state - Show compaction toast - Set session to compacting status - Call summarize endpoint with provider/model - Update SSE handler to clear compact status on session.compacted event The user sees a purple animated indicator and 'Compacting' text during the operation, matching the TUI experience. * Fix compact command to use break instead of return for model validation --------- Co-authored-by: Chris Scott <chris@cstech.dev>
This commit is contained in:
1 parent
516a894627
commit
a9ebee72c4
5 files changed
+47
-7
No files matched your search
@@ -2,8 +2,10 @@ import { useState, useCallback } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { createOpenCodeClient } from '@/api/opencode'
|
||||
import { useCreateSession } from '@/hooks/useOpenCode'
|
||||
import { useModelSelection } from '@/hooks/useModelSelection'
|
||||
import { showToast } from '@/lib/toast'
|
||||
import type { components } from '@/api/opencode-types'
|
||||
import { useSessionStatus } from '@/stores/sessionStatusStore'
|
||||
|
||||
type CommandType = components['schemas']['Command']
|
||||
|
||||
@@ -30,6 +32,8 @@ export function useCommandHandler({
|
||||
}: CommandHandlerProps) {
|
||||
const navigate = useNavigate()
|
||||
const createSession = useCreateSession(opcodeUrl, directory)
|
||||
const { model } = useModelSelection(opcodeUrl, directory)
|
||||
const setSessionStatus = useSessionStatus((state) => state.setStatus)
|
||||
const [loading, setLoading] = useState(false)
|
||||
|
||||
const executeCommand = useCallback(async (command: CommandType, args: string = '') => {
|
||||
@@ -96,11 +100,28 @@ export function useCommandHandler({
|
||||
onExportSession()
|
||||
}
|
||||
break
|
||||
|
||||
case 'compact':
|
||||
case 'summarize': {
|
||||
if (!model?.providerID || !model?.modelID) {
|
||||
showToast.error('No model selected. Please select a provider and model first.')
|
||||
break
|
||||
}
|
||||
|
||||
showToast.info('Compacting session...', { duration: 2000 })
|
||||
|
||||
setSessionStatus(sessionID, { type: 'compact' })
|
||||
|
||||
await client.summarizeSession(
|
||||
sessionID,
|
||||
model.providerID,
|
||||
model.modelID
|
||||
)
|
||||
break
|
||||
}
|
||||
|
||||
case 'share':
|
||||
case 'unshare':
|
||||
case 'compact':
|
||||
case 'summarize':
|
||||
case 'undo':
|
||||
case 'redo':
|
||||
case 'editor':
|
||||
@@ -119,10 +140,12 @@ export function useCommandHandler({
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to execute command:', error)
|
||||
showToast.error(`Command failed: ${error instanceof Error ? error.message : 'Unknown error'}`)
|
||||
setSessionStatus(sessionID, { type: 'idle' })
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}, [sessionID, opcodeUrl, directory, onShowSessionsDialog, onShowModelsDialog, onShowHelpDialog, onToggleDetails, onExportSession, createSession, navigate])
|
||||
}, [sessionID, opcodeUrl, directory, onShowSessionsDialog, onShowModelsDialog, onShowHelpDialog, onToggleDetails, onExportSession, createSession, navigate, model, setSessionStatus])
|
||||
|
||||
return {
|
||||
executeCommand,
|
||||
|
||||
Reference in new issue
Block a user