mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
Refactor task list display and enhance model selection with provider validation (#125)
This commit is contained in:
1 parent
b42f7b5010
commit
cb21e66339
9 files changed
+145
-204
No files matched your search
@@ -3,7 +3,6 @@ import { Pencil } from 'lucide-react'
|
||||
import { MessagePart } from './MessagePart'
|
||||
import { UserMessageActionButtons } from './UserMessageActionButtons'
|
||||
import { EditableUserMessage, ClickableUserMessage } from './EditableUserMessage'
|
||||
import { SessionTodoDisplay } from './SessionTodoDisplay'
|
||||
import { MessageError } from './MessageError'
|
||||
import type { MessageWithParts } from '@/api/types'
|
||||
import { useSessionStatusForSession } from '@/stores/sessionStatusStore'
|
||||
@@ -165,9 +164,6 @@ const state = latestTodoPart.state
|
||||
key={msg.info.id}
|
||||
className="flex flex-col group"
|
||||
>
|
||||
{msg.info.role === 'assistant' && streaming && (
|
||||
<SessionTodoDisplay sessionID={sessionID} />
|
||||
)}
|
||||
<div
|
||||
className={`w-full rounded-lg p-1.5 ${
|
||||
msg.info.role === 'user'
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { TodoListDisplay } from './TodoListDisplay'
|
||||
import { useState, useMemo } from 'react'
|
||||
import { ChevronDown, ChevronRight } from 'lucide-react'
|
||||
import { TodoItem } from './TodoItem'
|
||||
import { useSessionTodosForSession } from '@/stores/sessionTodosStore'
|
||||
import { useSessionStatusForSession } from '@/stores/sessionStatusStore'
|
||||
import type { components } from '@/api/opencode-types'
|
||||
|
||||
export type Todo = components['schemas']['Todo']
|
||||
@@ -10,20 +13,98 @@ interface SessionTodoDisplayProps {
|
||||
|
||||
export function SessionTodoDisplay({ sessionID }: SessionTodoDisplayProps) {
|
||||
const todos = useSessionTodosForSession(sessionID)
|
||||
const sessionStatus = useSessionStatusForSession(sessionID)
|
||||
const [isCollapsed, setIsCollapsed] = useState(false)
|
||||
|
||||
if (!sessionID || !todos || todos.length === 0) {
|
||||
const isSessionActive = sessionStatus.type === 'busy' || sessionStatus.type === 'compact' || sessionStatus.type === 'retry'
|
||||
|
||||
const stats = useMemo(() => {
|
||||
const completed = todos.filter((t) => t.status === 'completed').length
|
||||
const total = todos.length
|
||||
const percentage = total > 0 ? Math.round((completed / total) * 100) : 0
|
||||
return { completed, total, percentage }
|
||||
}, [todos])
|
||||
|
||||
const { inProgress, pending, completedTodos } = useMemo(() => ({
|
||||
inProgress: todos.filter((t) => t.status === 'in_progress'),
|
||||
pending: todos.filter((t) => t.status === 'pending'),
|
||||
completedTodos: todos.filter((t) => t.status === 'completed'),
|
||||
}), [todos])
|
||||
|
||||
const hasMultipleGroups =
|
||||
(inProgress.length > 0 ? 1 : 0) +
|
||||
(pending.length > 0 ? 1 : 0) +
|
||||
(completedTodos.length > 0 ? 1 : 0) >
|
||||
1
|
||||
|
||||
const renderGroup = (label: string, items: typeof todos) => {
|
||||
if (items.length === 0) return null
|
||||
return (
|
||||
<div className="mb-1 last:mb-0">
|
||||
{hasMultipleGroups && (
|
||||
<div className="text-[9px] font-medium text-muted-foreground mb-0.5 ml-4 uppercase tracking-wider opacity-70">
|
||||
{label} ({items.length})
|
||||
</div>
|
||||
)}
|
||||
<div>
|
||||
{items.map((todo) => (
|
||||
<div key={todo.id}>
|
||||
<TodoItem todo={todo} compact />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (!sessionID || !isSessionActive || todos.length === 0 || stats.completed === stats.total) {
|
||||
return null
|
||||
}
|
||||
|
||||
if (isCollapsed) {
|
||||
return (
|
||||
<div
|
||||
className="mb-2 px-3 py-2 bg-muted/50 rounded-lg cursor-pointer select-none"
|
||||
onClick={() => setIsCollapsed(false)}
|
||||
>
|
||||
<div className="flex items-center gap-2">
|
||||
<ChevronRight className="w-4 h-4 text-muted-foreground" />
|
||||
<span className="text-sm text-muted-foreground">
|
||||
Tasks: {stats.completed}/{stats.total} complete
|
||||
</span>
|
||||
<div className="flex-1 h-1.5 bg-secondary rounded-full overflow-hidden">
|
||||
<div
|
||||
className="h-full bg-green-500 transition-all duration-300"
|
||||
style={{ width: `${stats.percentage}%` }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="mb-2">
|
||||
<TodoListDisplay
|
||||
todos={todos}
|
||||
title="Task List"
|
||||
showCompleted={true}
|
||||
scrollCurrentOnly={true}
|
||||
isLoading={false}
|
||||
/>
|
||||
<div className="mb-2 rounded-lg overflow-hidden">
|
||||
<div
|
||||
className="flex items-center gap-2 px-3 py-2 bg-muted/50 cursor-pointer select-none"
|
||||
onClick={() => setIsCollapsed(true)}
|
||||
>
|
||||
<ChevronDown className="w-4 h-4 text-muted-foreground" />
|
||||
<span className="text-sm text-muted-foreground">
|
||||
Tasks: {stats.completed}/{stats.total} complete
|
||||
</span>
|
||||
<div className="flex-1 h-1.5 bg-secondary rounded-full overflow-hidden">
|
||||
<div
|
||||
className="h-full bg-green-500 transition-all duration-300"
|
||||
style={{ width: `${stats.percentage}%` }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="max-h-[80px] sm:max-h-[160px] overflow-y-auto p-1.5 sm:p-2 bg-muted/30">
|
||||
{renderGroup('In Progress', inProgress)}
|
||||
{renderGroup('Pending', pending)}
|
||||
{renderGroup('Completed', completedTodos)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,134 +0,0 @@
|
||||
import type { components } from '@/api/opencode-types'
|
||||
import { TodoItem } from './TodoItem'
|
||||
import { useEffect, useRef } from 'react'
|
||||
|
||||
export type Todo = components['schemas']['Todo']
|
||||
|
||||
interface TodoListDisplayProps {
|
||||
todos: Todo[]
|
||||
title?: string
|
||||
showCompleted?: boolean
|
||||
scrollCurrentOnly?: boolean
|
||||
isLoading?: boolean
|
||||
}
|
||||
|
||||
export function TodoListDisplay({
|
||||
todos,
|
||||
title = 'Todo List',
|
||||
showCompleted = true,
|
||||
scrollCurrentOnly = false,
|
||||
isLoading = false,
|
||||
}: TodoListDisplayProps) {
|
||||
const scrollRef = useRef<HTMLDivElement>(null)
|
||||
|
||||
// Filter completed tasks if not showing them
|
||||
const filteredTodos = showCompleted
|
||||
? todos
|
||||
: todos.filter((t) => t.status !== 'completed')
|
||||
|
||||
// Group by status for better organization
|
||||
const inProgress = filteredTodos.filter((t) => t.status === 'in_progress')
|
||||
const pending = filteredTodos.filter((t) => t.status === 'pending')
|
||||
const completed = showCompleted
|
||||
? filteredTodos.filter((t) => t.status === 'completed')
|
||||
: []
|
||||
|
||||
const hasMultipleGroups =
|
||||
(inProgress.length > 0 ? 1 : 0) +
|
||||
(pending.length > 0 ? 1 : 0) +
|
||||
(completed.length > 0 ? 1 : 0) >
|
||||
1
|
||||
|
||||
// Auto-scroll to current task (in_progress or first pending) within container only
|
||||
useEffect(() => {
|
||||
if (scrollRef.current && scrollCurrentOnly && filteredTodos.length > 0) {
|
||||
const container = scrollRef.current
|
||||
const currentElement = container.querySelector('[data-status="in_progress"], [data-status="pending"]') as HTMLElement | null
|
||||
if (currentElement) {
|
||||
const containerTop = container.scrollTop
|
||||
const containerHeight = container.clientHeight
|
||||
const elementTop = currentElement.offsetTop - container.offsetTop
|
||||
const elementHeight = currentElement.offsetHeight
|
||||
|
||||
if (elementTop < containerTop) {
|
||||
container.scrollTop = elementTop
|
||||
} else if (elementTop + elementHeight > containerTop + containerHeight) {
|
||||
container.scrollTop = elementTop + elementHeight - containerHeight
|
||||
}
|
||||
}
|
||||
}
|
||||
}, [todos, scrollCurrentOnly, filteredTodos.length])
|
||||
|
||||
// Empty states
|
||||
if (!todos || todos.length === 0) {
|
||||
return (
|
||||
<div className="text-sm text-muted-foreground italic">
|
||||
No tasks in the todo list.
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (filteredTodos.length === 0) {
|
||||
return (
|
||||
<div className="text-sm text-green-600 dark:text-green-400 flex items-center gap-2">
|
||||
<span className="text-lg">✓</span>
|
||||
<span>All tasks completed!</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const renderGroup = (label: string, items: Todo[], isCollapsible = false) => {
|
||||
if (items.length === 0) return null
|
||||
return (
|
||||
<div className="mb-1 last:mb-0">
|
||||
{hasMultipleGroups && (
|
||||
<div className="text-[9px] font-medium text-muted-foreground mb-0.5 ml-4 uppercase tracking-wider opacity-70">
|
||||
{label} ({items.length})
|
||||
</div>
|
||||
)}
|
||||
<div className={isCollapsible && items.length > 3 ? 'max-h-[60px] overflow-hidden relative after:absolute after:bottom-0 after:left-0 after:right-0 after:h-4 after:bg-gradient-to-t after:from-card after:to-transparent' : ''}>
|
||||
{items.map((todo) => (
|
||||
<div key={todo.id} data-status={todo.status}>
|
||||
<TodoItem todo={todo} compact />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const progress = filteredTodos.length > 0
|
||||
? Math.round((filteredTodos.filter(t => t.status === 'completed').length / filteredTodos.length) * 100)
|
||||
: 0
|
||||
|
||||
return (
|
||||
<div className="bg-card border rounded-lg overflow-hidden">
|
||||
{/* Compact header with progress bar */}
|
||||
<div className="px-2 py-1.5 border-b bg-muted/50 flex items-center gap-2">
|
||||
<span className="font-semibold text-xs">{title}</span>
|
||||
{isLoading && (
|
||||
<span className="w-2.5 h-2.5 border-2 border-yellow-500 border-t-transparent rounded-full animate-spin" />
|
||||
)}
|
||||
<div className="flex-1 h-1 bg-muted rounded-full overflow-hidden">
|
||||
<div
|
||||
className="h-full bg-green-600 transition-all duration-500"
|
||||
style={{ width: `${progress}%` }}
|
||||
/>
|
||||
</div>
|
||||
<span className="text-[10px] text-muted-foreground whitespace-nowrap tabular-nums">
|
||||
{filteredTodos.filter(t => t.status === 'completed').length}/{filteredTodos.length}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* Scrollable content area - optimized height for visibility */}
|
||||
<div
|
||||
ref={scrollRef}
|
||||
className={`max-h-[80px] sm:max-h-[160px] overflow-y-auto ${scrollCurrentOnly ? 'scroll-smooth' : ''} p-1.5 sm:p-2`}
|
||||
>
|
||||
{renderGroup('In Progress', inProgress)}
|
||||
{renderGroup('Pending', pending)}
|
||||
{renderGroup('Completed', completed, true)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -6,11 +6,9 @@ import { usePermissions, useQuestions } from '@/contexts/EventContext'
|
||||
import { detectFileReferences } from '@/lib/fileReferences'
|
||||
import { ExternalLink, Loader2 } from 'lucide-react'
|
||||
import { CopyButton } from '@/components/ui/copy-button'
|
||||
import { TodoListDisplay } from './TodoListDisplay'
|
||||
import { getToolSpecificRender } from './FileToolRender'
|
||||
|
||||
type ToolPart = components['schemas']['ToolPart']
|
||||
type Todo = components['schemas']['Todo']
|
||||
|
||||
interface ToolCallPartProps {
|
||||
part: ToolPart
|
||||
@@ -58,17 +56,6 @@ function ClickableJson({ json, onFileClick }: { json: unknown; onFileClick?: (fi
|
||||
return <pre className="bg-accent p-2 rounded text-xs overflow-x-auto whitespace-pre-wrap break-words">{parts}</pre>
|
||||
}
|
||||
|
||||
function parseTodoOutput(output: string): Todo[] | null {
|
||||
try {
|
||||
const parsed = JSON.parse(output)
|
||||
if (Array.isArray(parsed)) return parsed
|
||||
if (parsed && Array.isArray(parsed.todos)) return parsed.todos
|
||||
return null
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export function ToolCallPart({ part, onFileClick, onChildSessionClick }: ToolCallPartProps) {
|
||||
const { preferences } = useSettings()
|
||||
const { userBashCommands } = useUserBash()
|
||||
@@ -152,36 +139,7 @@ export function ToolCallPart({ part, onFileClick, onChildSessionClick }: ToolCal
|
||||
}
|
||||
}
|
||||
|
||||
const getTodoData = () => {
|
||||
if (part.tool !== 'todowrite' && part.tool !== 'todoread') {
|
||||
return null
|
||||
}
|
||||
|
||||
const state = part.state
|
||||
|
||||
if (state.status === 'completed') {
|
||||
if (state.metadata?.todos && Array.isArray(state.metadata.todos)) {
|
||||
return state.metadata.todos as Todo[]
|
||||
}
|
||||
if (state.output) {
|
||||
const parsed = parseTodoOutput(state.output)
|
||||
if (parsed) return parsed
|
||||
}
|
||||
}
|
||||
|
||||
if (state.status === 'running' && state.metadata?.todos && Array.isArray(state.metadata.todos)) {
|
||||
return state.metadata.todos as Todo[]
|
||||
}
|
||||
|
||||
if (state.input?.todos && Array.isArray(state.input.todos)) {
|
||||
return state.input.todos as Todo[]
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
const previewText = getPreviewText()
|
||||
const todoData = getTodoData()
|
||||
const isFileTool = ['read', 'write', 'edit'].includes(part.tool)
|
||||
|
||||
if (isTodoTool) {
|
||||
@@ -196,14 +154,9 @@ export function ToolCallPart({ part, onFileClick, onChildSessionClick }: ToolCal
|
||||
|
||||
if (part.state.status === 'running') {
|
||||
return (
|
||||
<div className="my-2">
|
||||
<TodoListDisplay
|
||||
todos={todoData || []}
|
||||
title="Task List"
|
||||
showCompleted={true}
|
||||
scrollCurrentOnly={true}
|
||||
isLoading={true}
|
||||
/>
|
||||
<div className="my-2 text-sm text-muted-foreground flex items-center gap-2">
|
||||
<Loader2 className="w-3 h-3 animate-spin" />
|
||||
<span>Updating task list...</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import { useEffect } from 'react'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { useConfig } from './useOpenCode'
|
||||
import { useOpenCodeClient } from './useOpenCode'
|
||||
import { useModelStore, type ModelSelection } from '@/stores/modelStore'
|
||||
import { getProviders } from '@/api/providers'
|
||||
|
||||
interface UseModelSelectionResult {
|
||||
model: ModelSelection | null
|
||||
@@ -14,11 +17,26 @@ export function useModelSelection(
|
||||
directory?: string
|
||||
): UseModelSelectionResult {
|
||||
const { data: config } = useConfig(opcodeUrl, directory)
|
||||
const { model, recentModels, setModel, syncFromConfig, getModelString } = useModelStore()
|
||||
const client = useOpenCodeClient(opcodeUrl, directory)
|
||||
|
||||
const { data: providersData } = useQuery({
|
||||
queryKey: ['opencode', 'providers', opcodeUrl, directory],
|
||||
queryFn: () => getProviders(),
|
||||
enabled: !!client,
|
||||
staleTime: 30000,
|
||||
})
|
||||
|
||||
const {
|
||||
model,
|
||||
recentModels,
|
||||
setModel,
|
||||
validateAndSyncModel,
|
||||
getModelString
|
||||
} = useModelStore()
|
||||
|
||||
useEffect(() => {
|
||||
syncFromConfig(config?.model)
|
||||
}, [config?.model, syncFromConfig])
|
||||
validateAndSyncModel(config?.model, providersData?.providers)
|
||||
}, [config?.model, providersData, validateAndSyncModel])
|
||||
|
||||
return {
|
||||
model,
|
||||
|
||||
@@ -7,6 +7,7 @@ export function invalidateConfigCaches(queryClient: QueryClient) {
|
||||
queryClient.invalidateQueries({ queryKey: ['health'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['mcp-status'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['providers'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['opencode', 'providers'] })
|
||||
}
|
||||
|
||||
export function invalidateSettingsCaches(queryClient: QueryClient, userId = 'default') {
|
||||
|
||||
@@ -26,6 +26,7 @@ import {
|
||||
import { Plug, FolderOpen, Plus, GitBranch, Loader2, GitCommitHorizontal, ShieldOff } from "lucide-react";
|
||||
import { PendingActionsGroup } from "@/components/notifications/PendingActionsGroup";
|
||||
import { showToast } from "@/lib/toast";
|
||||
import { invalidateConfigCaches } from "@/lib/queryInvalidation";
|
||||
|
||||
export function RepoDetail() {
|
||||
const { id } = useParams<{ id: string }>();
|
||||
@@ -266,6 +267,7 @@ export function RepoDetail() {
|
||||
...repo,
|
||||
openCodeConfigName: configName,
|
||||
});
|
||||
invalidateConfigCaches(queryClient);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -36,6 +36,7 @@ import { useQuestions } from "@/contexts/EventContext";
|
||||
import { QuestionPrompt } from "@/components/session/QuestionPrompt";
|
||||
import { PendingActionsGroup } from "@/components/notifications/PendingActionsGroup";
|
||||
import { SourceControlPanel } from "@/components/source-control";
|
||||
import { SessionTodoDisplay } from "@/components/message/SessionTodoDisplay";
|
||||
|
||||
const compareMessageIds = (id1: string, id2: string): number => {
|
||||
const num1 = parseInt(id1, 10)
|
||||
@@ -404,6 +405,8 @@ export function SessionDetail() {
|
||||
</Header.Actions>
|
||||
</Header>
|
||||
|
||||
<SessionTodoDisplay sessionID={sessionId} />
|
||||
|
||||
<div className="flex-1 overflow-hidden flex flex-col relative">
|
||||
<div key={sessionId} ref={messageContainerRef} className="flex-1 overflow-y-auto overflow-x-hidden pb-28 overscroll-contain [mask-image:linear-gradient(to_bottom,transparent,black_16px,black)]">
|
||||
{repoLoading || sessionLoading || messagesLoading ? (
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { create } from 'zustand'
|
||||
import { persist } from 'zustand/middleware'
|
||||
import type { Provider } from '@/api/providers'
|
||||
|
||||
export interface ModelSelection {
|
||||
providerID: string
|
||||
@@ -13,7 +14,8 @@ interface ModelStore {
|
||||
lastConfigModel: string | undefined
|
||||
|
||||
setModel: (model: ModelSelection) => void
|
||||
syncFromConfig: (configModel: string | undefined) => void
|
||||
syncFromConfig: (configModel: string | undefined, force?: boolean) => void
|
||||
validateAndSyncModel: (configModel: string | undefined, providers?: Provider[]) => void
|
||||
getModelString: () => string | null
|
||||
setVariant: (model: ModelSelection, variant: string | undefined) => void
|
||||
getVariant: (model: ModelSelection) => string | undefined
|
||||
@@ -53,9 +55,9 @@ export const useModelStore = create<ModelStore>()(
|
||||
})
|
||||
},
|
||||
|
||||
syncFromConfig: (configModel: string | undefined) => {
|
||||
syncFromConfig: (configModel: string | undefined, force = false) => {
|
||||
const state = get()
|
||||
if (state.lastConfigModel === configModel) return
|
||||
if (!force && state.lastConfigModel === configModel) return
|
||||
|
||||
if (configModel) {
|
||||
const parsed = parseModelString(configModel)
|
||||
@@ -74,6 +76,25 @@ export const useModelStore = create<ModelStore>()(
|
||||
set({ lastConfigModel: configModel })
|
||||
},
|
||||
|
||||
validateAndSyncModel: (configModel: string | undefined, providers?: Provider[]) => {
|
||||
if (!configModel) return
|
||||
|
||||
const state = get()
|
||||
|
||||
if (!providers || !state.model) {
|
||||
get().syncFromConfig(configModel)
|
||||
return
|
||||
}
|
||||
|
||||
const modelExists = providers.some(
|
||||
(p) => p.id === state.model!.providerID && p.models && state.model!.modelID in p.models
|
||||
)
|
||||
|
||||
if (!modelExists) {
|
||||
get().syncFromConfig(configModel, true)
|
||||
}
|
||||
},
|
||||
|
||||
getModelString: () => {
|
||||
const { model } = get()
|
||||
if (!model) return null
|
||||
|
||||
Reference in new issue
Block a user