mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +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
@@ -82,6 +82,14 @@ export class OpenCodeClient {
|
||||
return response.data
|
||||
}
|
||||
|
||||
async summarizeSession(sessionID: string, providerID: string, modelID: string) {
|
||||
const response = await this.client.post(`/session/${sessionID}/summarize`, {
|
||||
providerID,
|
||||
modelID
|
||||
})
|
||||
return response.data
|
||||
}
|
||||
|
||||
async getConfig() {
|
||||
const response = await this.client.get<ConfigResponse>('/config')
|
||||
return response.data
|
||||
|
||||
@@ -19,7 +19,7 @@ export const SessionStatusIndicator = memo(function SessionStatusIndicator({
|
||||
const [retryCountdown, setRetryCountdown] = useState(0)
|
||||
|
||||
useEffect(() => {
|
||||
if (status.type !== 'busy' && status.type !== 'retry') {
|
||||
if (status.type !== 'busy' && status.type !== 'retry' && status.type !== 'compact') {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -79,6 +79,13 @@ export const SessionStatusIndicator = memo(function SessionStatusIndicator({
|
||||
return 'bg-amber-500/20'
|
||||
}
|
||||
|
||||
if (statusType === 'compact') {
|
||||
if (intensity > 0.8) return 'bg-purple-500'
|
||||
if (intensity > 0.5) return 'bg-purple-500/70'
|
||||
if (intensity > 0.2) return 'bg-purple-500/40'
|
||||
return 'bg-purple-500/20'
|
||||
}
|
||||
|
||||
if (intensity > 0.8) return 'bg-blue-500'
|
||||
if (intensity > 0.5) return 'bg-blue-500/70'
|
||||
if (intensity > 0.2) return 'bg-blue-500/40'
|
||||
@@ -120,7 +127,7 @@ export const CompactStatusIndicator = memo(function CompactStatusIndicator({
|
||||
const [frame, setFrame] = useState(0)
|
||||
|
||||
useEffect(() => {
|
||||
if (status.type === 'idle') return
|
||||
if (status.type !== 'busy' && status.type !== 'retry' && status.type !== 'compact') return
|
||||
|
||||
const interval = setInterval(() => {
|
||||
setFrame(prev => (prev + 1) % 8)
|
||||
@@ -134,13 +141,13 @@ export const CompactStatusIndicator = memo(function CompactStatusIndicator({
|
||||
}
|
||||
|
||||
const pulseFrames = ['●', '◐', '○', '◑', '●', '◐', '○', '◑']
|
||||
const color = status.type === 'retry' ? 'text-amber-500' : 'text-blue-500'
|
||||
const color = status.type === 'retry' ? 'text-amber-500' : status.type === 'compact' ? 'text-purple-500' : 'text-blue-500'
|
||||
|
||||
return (
|
||||
<span className={`inline-flex items-center gap-1.5 ${className}`}>
|
||||
<span className={`${color} text-sm font-mono`}>{pulseFrames[frame]}</span>
|
||||
<span className={`text-xs ${color}`}>
|
||||
{status.type === 'retry' ? `Retry #${status.attempt}` : 'Working'}
|
||||
{status.type === 'retry' ? `Retry #${status.attempt}` : status.type === 'compact' ? 'Compacting' : 'Working'}
|
||||
</span>
|
||||
</span>
|
||||
)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -253,6 +253,7 @@ export const useSSE = (opcodeUrl: string | null | undefined, directory?: string)
|
||||
if (!('sessionID' in event.properties)) break
|
||||
|
||||
const { sessionID } = event.properties
|
||||
setSessionStatus(sessionID, { type: 'idle' })
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ['opencode', 'messages', opcodeUrl, sessionID, directory]
|
||||
})
|
||||
|
||||
@@ -3,6 +3,7 @@ import { create } from 'zustand'
|
||||
export type SessionStatusType =
|
||||
| { type: 'idle' }
|
||||
| { type: 'busy' }
|
||||
| { type: 'compact' }
|
||||
| { type: 'retry'; attempt: number; message: string; next: number }
|
||||
|
||||
interface SessionStatusStore {
|
||||
|
||||
Reference in new issue
Block a user