mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
feat(frontend): add simple chat mode (#190)
* loop: simple-chat-mode completed after 1 iterations * feat(frontend): add simple chat mode for user messages and clean up redundant optimistic filtering * refactor(frontend): consolidate status indicators and simplify simple chat mode - Merge MiniScanner and CompactStatusIndicator into SessionStatusIndicator with size and showLabel props - Hide step-finish cost/token display in simpleChatMode - Update SessionCard and PromptInput to use unified SessionStatusIndicator - Add tests for step-finish rendering in simpleChatMode
This commit is contained in:
1 parent
b61a3c83d1
commit
adf77516e5
12 files changed
+493
-221
No files matched your search
@@ -48,9 +48,10 @@ export interface UserPreferences {
|
||||
defaultModel?: string
|
||||
defaultAgent?: string
|
||||
autoScroll: boolean
|
||||
showReasoning: boolean
|
||||
expandToolCalls: boolean
|
||||
expandDiffs: boolean
|
||||
expandToolCalls: boolean
|
||||
showReasoning: boolean
|
||||
simpleChatMode: boolean
|
||||
leaderKey?: string
|
||||
directShortcuts?: string[]
|
||||
keyboardShortcuts: Record<string, string>
|
||||
|
||||
@@ -66,10 +66,12 @@ export function FileToolRender({ part, filediff, filePath, content, toolName, on
|
||||
const { preferences } = useSettings()
|
||||
const isReadTool = toolName === 'Read'
|
||||
const isEditTool = toolName === 'Edit'
|
||||
const isWriteTool = toolName === 'Write'
|
||||
const hasExpandableContent = !isReadTool && (filediff || content)
|
||||
|
||||
const defaultExpanded = isEditTool
|
||||
? (preferences?.expandDiffs ?? true)
|
||||
const isFileMutatingTool = isEditTool || isWriteTool
|
||||
const defaultExpanded = isFileMutatingTool
|
||||
? (preferences?.expandDiffs ?? true)
|
||||
: (preferences?.expandToolCalls ?? false)
|
||||
const [expanded, setExpanded] = useState(defaultExpanded)
|
||||
|
||||
|
||||
@@ -5,12 +5,17 @@ import type { MessagePart as MessagePartType } from '@/api/types'
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
useTTS: vi.fn(),
|
||||
useSettings: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useTTS', () => ({
|
||||
useTTS: mocks.useTTS,
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useSettings', () => ({
|
||||
useSettings: mocks.useSettings,
|
||||
}))
|
||||
|
||||
interface MockTTSReturn {
|
||||
speakMessage: ReturnType<typeof vi.fn>
|
||||
stop: ReturnType<typeof vi.fn>
|
||||
@@ -20,6 +25,21 @@ interface MockTTSReturn {
|
||||
isEnabled: boolean
|
||||
}
|
||||
|
||||
interface MockSettingsReturn {
|
||||
preferences: {
|
||||
simpleChatMode: boolean
|
||||
showReasoning: boolean
|
||||
expandToolCalls: boolean
|
||||
expandDiffs: boolean
|
||||
autoScroll: boolean
|
||||
theme: 'dark' | 'light' | 'system'
|
||||
mode: 'plan' | 'build'
|
||||
} | undefined
|
||||
isLoading: boolean
|
||||
updateSettings: ReturnType<typeof vi.fn>
|
||||
isUpdating: boolean
|
||||
}
|
||||
|
||||
describe('MessagePart', () => {
|
||||
const mockSpeakMessage = vi.fn()
|
||||
const mockStop = vi.fn()
|
||||
@@ -27,6 +47,20 @@ describe('MessagePart', () => {
|
||||
beforeEach(() => {
|
||||
mockSpeakMessage.mockClear()
|
||||
mockStop.mockClear()
|
||||
mocks.useSettings.mockReturnValue({
|
||||
preferences: {
|
||||
simpleChatMode: false,
|
||||
showReasoning: false,
|
||||
expandToolCalls: false,
|
||||
expandDiffs: true,
|
||||
autoScroll: true,
|
||||
theme: 'dark' as const,
|
||||
mode: 'build' as const,
|
||||
},
|
||||
isLoading: false,
|
||||
updateSettings: vi.fn(),
|
||||
isUpdating: false,
|
||||
})
|
||||
})
|
||||
|
||||
const setup = (options: {
|
||||
@@ -47,6 +81,15 @@ describe('MessagePart', () => {
|
||||
mocks.useTTS.mockReturnValue(mockTTS)
|
||||
}
|
||||
|
||||
const setupSettings = (preferences: MockSettingsReturn['preferences']) => {
|
||||
mocks.useSettings.mockReturnValue({
|
||||
preferences,
|
||||
isLoading: false,
|
||||
updateSettings: vi.fn(),
|
||||
isUpdating: false,
|
||||
})
|
||||
}
|
||||
|
||||
const createStepFinishPart = (messageID: string): MessagePartType => ({
|
||||
type: 'step-finish',
|
||||
messageID,
|
||||
@@ -223,4 +266,311 @@ describe('MessagePart', () => {
|
||||
|
||||
expect(screen.getByRole('button')).not.toHaveClass('bg-red-500/20')
|
||||
})
|
||||
|
||||
describe('simpleChatMode', () => {
|
||||
const createToolPart = (): MessagePartType => ({
|
||||
type: 'tool',
|
||||
tool: 'edit',
|
||||
sessionID: 'test-session',
|
||||
state: {
|
||||
status: 'completed',
|
||||
input: { filePath: '/test/file.txt' },
|
||||
time: { start: Date.now(), end: Date.now() + 100 },
|
||||
},
|
||||
})
|
||||
|
||||
const createPatchPart = (): MessagePartType => ({
|
||||
type: 'patch',
|
||||
hash: 'abc123',
|
||||
files: ['/test/file.txt'],
|
||||
sessionID: 'test-session',
|
||||
})
|
||||
|
||||
const createReasoningPart = (): MessagePartType => ({
|
||||
type: 'reasoning',
|
||||
text: 'This is the reasoning text',
|
||||
sessionID: 'test-session',
|
||||
})
|
||||
|
||||
const createSnapshotPart = (): MessagePartType => ({
|
||||
type: 'snapshot',
|
||||
snapshot: 'snapshot-data',
|
||||
sessionID: 'test-session',
|
||||
})
|
||||
|
||||
const createAgentPart = (): MessagePartType => ({
|
||||
type: 'agent',
|
||||
name: 'test-agent',
|
||||
sessionID: 'test-session',
|
||||
})
|
||||
|
||||
const createStepFinishPart = (): MessagePartType => ({
|
||||
type: 'step-finish',
|
||||
messageID: 'test-message',
|
||||
sessionID: 'test-session',
|
||||
cost: 0.01,
|
||||
tokens: {
|
||||
input: 100,
|
||||
output: 50,
|
||||
cache: { read: 0, write: 0 },
|
||||
},
|
||||
time: {
|
||||
start: Date.now(),
|
||||
end: Date.now() + 100,
|
||||
},
|
||||
})
|
||||
|
||||
const createTextPart = (): MessagePartType => ({
|
||||
type: 'text',
|
||||
text: 'Hello, this is a text message',
|
||||
sessionID: 'test-session',
|
||||
})
|
||||
|
||||
it('renders null for tool part when simpleChatMode is true', () => {
|
||||
setupSettings({
|
||||
simpleChatMode: true,
|
||||
showReasoning: false,
|
||||
expandToolCalls: false,
|
||||
expandDiffs: true,
|
||||
autoScroll: true,
|
||||
theme: 'dark',
|
||||
mode: 'build',
|
||||
})
|
||||
|
||||
const part = createToolPart()
|
||||
const { container } = render(<MessagePart part={part} />)
|
||||
|
||||
expect(container.firstChild).toBeNull()
|
||||
})
|
||||
|
||||
it('renders null for patch part when simpleChatMode is true', () => {
|
||||
setupSettings({
|
||||
simpleChatMode: true,
|
||||
showReasoning: false,
|
||||
expandToolCalls: false,
|
||||
expandDiffs: true,
|
||||
autoScroll: true,
|
||||
theme: 'dark',
|
||||
mode: 'build',
|
||||
})
|
||||
|
||||
const part = createPatchPart()
|
||||
const { container } = render(<MessagePart part={part} />)
|
||||
|
||||
expect(container.firstChild).toBeNull()
|
||||
})
|
||||
|
||||
it('renders null for reasoning part when simpleChatMode is true', () => {
|
||||
setupSettings({
|
||||
simpleChatMode: true,
|
||||
showReasoning: true,
|
||||
expandToolCalls: false,
|
||||
expandDiffs: true,
|
||||
autoScroll: true,
|
||||
theme: 'dark',
|
||||
mode: 'build',
|
||||
})
|
||||
|
||||
const part = createReasoningPart()
|
||||
const { container } = render(<MessagePart part={part} />)
|
||||
|
||||
expect(container.firstChild).toBeNull()
|
||||
})
|
||||
|
||||
it('renders null for snapshot part when simpleChatMode is true', () => {
|
||||
setupSettings({
|
||||
simpleChatMode: true,
|
||||
showReasoning: false,
|
||||
expandToolCalls: false,
|
||||
expandDiffs: true,
|
||||
autoScroll: true,
|
||||
theme: 'dark',
|
||||
mode: 'build',
|
||||
})
|
||||
|
||||
const part = createSnapshotPart()
|
||||
const { container } = render(<MessagePart part={part} />)
|
||||
|
||||
expect(container.firstChild).toBeNull()
|
||||
})
|
||||
|
||||
it('renders null for agent part when simpleChatMode is true', () => {
|
||||
setupSettings({
|
||||
simpleChatMode: true,
|
||||
showReasoning: false,
|
||||
expandToolCalls: false,
|
||||
expandDiffs: true,
|
||||
autoScroll: true,
|
||||
theme: 'dark',
|
||||
mode: 'build',
|
||||
})
|
||||
|
||||
const part = createAgentPart()
|
||||
const { container } = render(<MessagePart part={part} />)
|
||||
|
||||
expect(container.firstChild).toBeNull()
|
||||
})
|
||||
|
||||
it('renders text part when simpleChatMode is true', () => {
|
||||
setupSettings({
|
||||
simpleChatMode: true,
|
||||
showReasoning: false,
|
||||
expandToolCalls: false,
|
||||
expandDiffs: true,
|
||||
autoScroll: true,
|
||||
theme: 'dark',
|
||||
mode: 'build',
|
||||
})
|
||||
|
||||
const part = createTextPart()
|
||||
render(<MessagePart part={part} />)
|
||||
|
||||
expect(screen.getByText('Hello, this is a text message')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders tool part when simpleChatMode is false', () => {
|
||||
setupSettings({
|
||||
simpleChatMode: false,
|
||||
showReasoning: false,
|
||||
expandToolCalls: false,
|
||||
expandDiffs: true,
|
||||
autoScroll: true,
|
||||
theme: 'dark',
|
||||
mode: 'build',
|
||||
})
|
||||
|
||||
const part = createToolPart()
|
||||
const { container } = render(<MessagePart part={part} />)
|
||||
|
||||
expect(container.firstChild).not.toBeNull()
|
||||
})
|
||||
|
||||
it('renders patch part when simpleChatMode is false', () => {
|
||||
setupSettings({
|
||||
simpleChatMode: false,
|
||||
showReasoning: false,
|
||||
expandToolCalls: false,
|
||||
expandDiffs: true,
|
||||
autoScroll: true,
|
||||
theme: 'dark',
|
||||
mode: 'build',
|
||||
})
|
||||
|
||||
const part = createPatchPart()
|
||||
const { container } = render(<MessagePart part={part} />)
|
||||
|
||||
expect(container.firstChild).not.toBeNull()
|
||||
})
|
||||
|
||||
it('renders snapshot part when simpleChatMode is false', () => {
|
||||
setupSettings({
|
||||
simpleChatMode: false,
|
||||
showReasoning: false,
|
||||
expandToolCalls: false,
|
||||
expandDiffs: true,
|
||||
autoScroll: true,
|
||||
theme: 'dark',
|
||||
mode: 'build',
|
||||
})
|
||||
|
||||
const part = createSnapshotPart()
|
||||
const { container } = render(<MessagePart part={part} />)
|
||||
|
||||
expect(container.firstChild).not.toBeNull()
|
||||
})
|
||||
|
||||
it('renders agent part when simpleChatMode is false', () => {
|
||||
setupSettings({
|
||||
simpleChatMode: false,
|
||||
showReasoning: false,
|
||||
expandToolCalls: false,
|
||||
expandDiffs: true,
|
||||
autoScroll: true,
|
||||
theme: 'dark',
|
||||
mode: 'build',
|
||||
})
|
||||
|
||||
const part = createAgentPart()
|
||||
const { container } = render(<MessagePart part={part} />)
|
||||
|
||||
expect(container.firstChild).not.toBeNull()
|
||||
})
|
||||
|
||||
it('renders null for step-finish part when simpleChatMode is true', () => {
|
||||
setupSettings({
|
||||
simpleChatMode: true,
|
||||
showReasoning: false,
|
||||
expandToolCalls: false,
|
||||
expandDiffs: true,
|
||||
autoScroll: true,
|
||||
theme: 'dark',
|
||||
mode: 'build',
|
||||
})
|
||||
|
||||
const part = createStepFinishPart()
|
||||
const { container } = render(<MessagePart part={part} />)
|
||||
|
||||
expect(container.firstChild).toBeNull()
|
||||
})
|
||||
|
||||
it('renders step-finish part when simpleChatMode is false', () => {
|
||||
setupSettings({
|
||||
simpleChatMode: false,
|
||||
showReasoning: false,
|
||||
expandToolCalls: false,
|
||||
expandDiffs: true,
|
||||
autoScroll: true,
|
||||
theme: 'dark',
|
||||
mode: 'build',
|
||||
})
|
||||
|
||||
const part = createStepFinishPart()
|
||||
const { container } = render(<MessagePart part={part} />)
|
||||
|
||||
expect(container.firstChild).not.toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('showReasoning', () => {
|
||||
const createReasoningPart = (): MessagePartType => ({
|
||||
type: 'reasoning',
|
||||
text: 'This is the reasoning text',
|
||||
sessionID: 'test-session',
|
||||
})
|
||||
|
||||
it('renders null for reasoning part when showReasoning is false', () => {
|
||||
setupSettings({
|
||||
simpleChatMode: false,
|
||||
showReasoning: false,
|
||||
expandToolCalls: false,
|
||||
expandDiffs: true,
|
||||
autoScroll: true,
|
||||
theme: 'dark',
|
||||
mode: 'build',
|
||||
})
|
||||
|
||||
const part = createReasoningPart()
|
||||
const { container } = render(<MessagePart part={part} />)
|
||||
|
||||
expect(container.firstChild).toBeNull()
|
||||
})
|
||||
|
||||
it('renders reasoning part when showReasoning is true', () => {
|
||||
setupSettings({
|
||||
simpleChatMode: false,
|
||||
showReasoning: true,
|
||||
expandToolCalls: false,
|
||||
expandDiffs: true,
|
||||
autoScroll: true,
|
||||
theme: 'dark',
|
||||
mode: 'build',
|
||||
})
|
||||
|
||||
const part = createReasoningPart()
|
||||
render(<MessagePart part={part} />)
|
||||
|
||||
expect(screen.getByText('This is the reasoning text')).toBeInTheDocument()
|
||||
expect(screen.getByText('Reasoning')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -7,6 +7,7 @@ import { ToolCallPart } from './ToolCallPart'
|
||||
import { RetryPart } from './RetryPart'
|
||||
import { useTTS } from '@/hooks/useTTS'
|
||||
import { useMobile } from '@/hooks/useMobile'
|
||||
import { useSettings } from '@/hooks/useSettings'
|
||||
import { CopyButton } from '@/components/ui/copy-button'
|
||||
|
||||
type RetryPartType = components['schemas']['RetryPart']
|
||||
@@ -100,6 +101,9 @@ function TTSButton({ messageId, content, className = "" }: TTSButtonProps) {
|
||||
}
|
||||
|
||||
export const MessagePart = memo(function MessagePart({ part, role, allParts, partIndex, onFileClick, onChildSessionClick, messageTextContent }: MessagePartProps) {
|
||||
const { preferences } = useSettings()
|
||||
const simpleChatMode = preferences?.simpleChatMode ?? false
|
||||
const showReasoning = preferences?.showReasoning ?? false
|
||||
const copyableContent = getCopyableContent(part, allParts)
|
||||
const isMobile = useMobile()
|
||||
|
||||
@@ -113,10 +117,13 @@ export const MessagePart = memo(function MessagePart({ part, role, allParts, par
|
||||
}
|
||||
return <TextPart part={part} />
|
||||
case 'patch':
|
||||
if (simpleChatMode) return null
|
||||
return <PatchPart part={part} onFileClick={onFileClick} />
|
||||
case 'tool':
|
||||
if (simpleChatMode) return null
|
||||
return <ToolCallPart part={part} onFileClick={onFileClick} onChildSessionClick={onChildSessionClick} />
|
||||
case 'reasoning':
|
||||
if (simpleChatMode || !showReasoning) return null
|
||||
return (
|
||||
<details className="border border-border rounded-lg my-2">
|
||||
<summary className="px-4 py-2 bg-muted hover:bg-accent cursor-pointer text-sm font-medium">
|
||||
@@ -128,29 +135,33 @@ export const MessagePart = memo(function MessagePart({ part, role, allParts, par
|
||||
</details>
|
||||
)
|
||||
case 'snapshot':
|
||||
if (simpleChatMode) return null
|
||||
return (
|
||||
<div className="border border-border rounded-lg p-4 my-2 bg-card">
|
||||
<div className="text-xs text-muted-foreground font-mono">Snapshot: {part.snapshot}</div>
|
||||
</div>
|
||||
)
|
||||
case 'agent':
|
||||
if (simpleChatMode) return null
|
||||
return (
|
||||
<div className="border border-border rounded-lg p-4 my-2 bg-card">
|
||||
<div className="text-sm font-medium text-blue-600 dark:text-blue-400">Agent: {part.name}</div>
|
||||
</div>
|
||||
)
|
||||
case 'step-finish': {
|
||||
const isFree = part.cost === 0
|
||||
const totalTokens = part.tokens.input + part.tokens.output + (part.tokens.cache?.read || 0)
|
||||
const costText = isMobile && isFree ? null : <span>${part.cost.toFixed(4)} • {totalTokens} tokens</span>
|
||||
return (
|
||||
<div className="text-xs text-muted-foreground my-1 flex items-center gap-2">
|
||||
{costText}
|
||||
<CopyButton content={copyableContent} title="Copy step complete" />
|
||||
{messageTextContent && part.messageID && <TTSButton messageId={part.messageID} content={messageTextContent} />}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
case 'step-finish':
|
||||
if (simpleChatMode) return null
|
||||
{
|
||||
const isFree = part.cost === 0
|
||||
const totalTokens = part.tokens.input + part.tokens.output + (part.tokens.cache?.read || 0)
|
||||
const costText = isMobile && isFree ? null : <span>${part.cost.toFixed(4)} • {totalTokens} tokens</span>
|
||||
return (
|
||||
<div className="text-xs text-muted-foreground my-1 flex items-center gap-2">
|
||||
{costText}
|
||||
<CopyButton content={copyableContent} title="Copy step complete" />
|
||||
{messageTextContent && part.messageID && <TTSButton messageId={part.messageID} content={messageTextContent} />}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
case 'file':
|
||||
return (
|
||||
<span className="inline-flex items-center gap-1 px-2 py-1 rounded bg-muted border border-border text-sm text-foreground">
|
||||
|
||||
@@ -7,6 +7,7 @@ import { MessageError } from './MessageError'
|
||||
import type { Message, Part, MessageWithParts } from '@/api/types'
|
||||
import { useSessionStatusForSession } from '@/stores/sessionStatusStore'
|
||||
import { useSessionTodos } from '@/stores/sessionTodosStore'
|
||||
import { useSettings } from '@/hooks/useSettings'
|
||||
import type { components } from '@/api/opencode-types'
|
||||
import type { Todo } from '@/components/message/SessionTodoDisplay'
|
||||
import type { OpenCodeError } from '@/lib/opencode-errors'
|
||||
@@ -78,6 +79,7 @@ interface MessageRowProps {
|
||||
handleStartEditUserMessage: (userMessageId: string, assistantMessageId: string) => void
|
||||
handleCancelEdit: () => void
|
||||
model?: string
|
||||
simpleChatMode: boolean
|
||||
}
|
||||
|
||||
const MessageRow = memo(function MessageRow({
|
||||
@@ -98,6 +100,7 @@ const MessageRow = memo(function MessageRow({
|
||||
handleStartEditUserMessage,
|
||||
handleCancelEdit,
|
||||
model,
|
||||
simpleChatMode,
|
||||
}: MessageRowProps) {
|
||||
const msg = msgWithParts.info
|
||||
const parts = msgWithParts.parts
|
||||
@@ -185,6 +188,12 @@ const MessageRow = memo(function MessageRow({
|
||||
onClick={() => handleStartEditUserMessage(msg.id, nextAssistantMsg.id)}
|
||||
isEditable={false}
|
||||
/>
|
||||
) : msg.role === 'user' && simpleChatMode ? (
|
||||
<ClickableUserMessage
|
||||
content={messageTextContent}
|
||||
onClick={() => {}}
|
||||
isEditable={false}
|
||||
/>
|
||||
) : parts.length > 0 ? (
|
||||
parts.map((part: Part, partIndex: number) => (
|
||||
<div key={`${msg.id}-${part.id}-${partIndex}`}>
|
||||
@@ -222,6 +231,8 @@ export const MessageThread = memo(function MessageThread({
|
||||
const [editingUserMessageId, setEditingUserMessageId] = useState<string | null>(null)
|
||||
const [editingForAssistantId, setEditingForAssistantId] = useState<string | null>(null)
|
||||
const sessionStatus = useSessionStatusForSession(sessionID)
|
||||
const { preferences } = useSettings()
|
||||
const simpleChatMode = preferences?.simpleChatMode ?? false
|
||||
|
||||
const pendingAssistantId = useMemo(() => {
|
||||
if (!messages) return undefined
|
||||
@@ -316,6 +327,7 @@ export const MessageThread = memo(function MessageThread({
|
||||
handleStartEditUserMessage={handleStartEditUserMessage}
|
||||
handleCancelEdit={handleCancelEdit}
|
||||
model={model}
|
||||
simpleChatMode={simpleChatMode}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
@@ -1065,7 +1065,7 @@ return (
|
||||
/>
|
||||
{hasActiveStream ? (
|
||||
<div className="px-2.5 py-1.5 md:px-3 md:py-2 rounded-lg text-xs md:text-sm font-medium text-muted-foreground max-w-[120px] md:max-w-[180px]">
|
||||
<SessionStatusIndicator sessionID={sessionID} />
|
||||
<SessionStatusIndicator sessionID={sessionID} showLabel />
|
||||
</div>
|
||||
) : (
|
||||
!hideSecondaryButtons && (
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useRef, useEffect } from "react";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { Checkbox } from "@/components/ui/checkbox";
|
||||
import { MiniScanner } from "@/components/ui/mini-scanner";
|
||||
import { SessionStatusIndicator } from "@/components/ui/session-status-indicator";
|
||||
import { Trash2, Clock } from "lucide-react";
|
||||
import { formatDistanceToNow } from "date-fns";
|
||||
import type { Session } from "@/api/types";
|
||||
@@ -82,17 +82,17 @@ export const SessionCard = ({
|
||||
{manageMode ? (
|
||||
<div className="flex items-start gap-2 flex-1 min-w-0">
|
||||
<div className="flex flex-col items-center gap-2 flex-shrink-0">
|
||||
<Checkbox
|
||||
checked={isSelected}
|
||||
onCheckedChange={(checked) => {
|
||||
onToggleSelection(checked === true);
|
||||
}}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
}}
|
||||
className="w-5 h-5 flex-shrink-0"
|
||||
/>
|
||||
<MiniScanner sessionID={session.id} />
|
||||
<Checkbox
|
||||
checked={isSelected}
|
||||
onCheckedChange={(checked) => {
|
||||
onToggleSelection(checked === true);
|
||||
}}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
}}
|
||||
className="w-5 h-5 flex-shrink-0"
|
||||
/>
|
||||
<SessionStatusIndicator sessionID={session.id} size="sm" />
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center gap-1">
|
||||
@@ -122,7 +122,7 @@ export const SessionCard = ({
|
||||
addSuffix: true,
|
||||
})}
|
||||
</span>
|
||||
<MiniScanner sessionID={session.id} />
|
||||
<SessionStatusIndicator sessionID={session.id} size="sm" />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -67,6 +67,20 @@ export function GeneralSettings() {
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-row items-center justify-between rounded-lg border border-border p-4">
|
||||
<div className="space-y-0.5">
|
||||
<Label htmlFor="simpleChatMode" className="text-base">Simple chat mode</Label>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Show only your messages and the assistant's replies. Hides tool calls, reasoning, diffs, and agent details.
|
||||
</p>
|
||||
</div>
|
||||
<Switch
|
||||
id="simpleChatMode"
|
||||
checked={preferences?.simpleChatMode ?? false}
|
||||
onCheckedChange={(checked) => updateSettings({ simpleChatMode: checked })}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-row items-center justify-between rounded-lg border border-border p-4">
|
||||
<div className="space-y-0.5">
|
||||
<Label htmlFor="autoScroll" className="text-base">Auto-scroll</Label>
|
||||
@@ -81,47 +95,51 @@ export function GeneralSettings() {
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-row items-center justify-between rounded-lg border border-border p-4">
|
||||
<div className="space-y-0.5">
|
||||
<Label htmlFor="showReasoning" className="text-base">Show reasoning</Label>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Display model reasoning and thought process
|
||||
</p>
|
||||
</div>
|
||||
<Switch
|
||||
id="showReasoning"
|
||||
checked={preferences?.showReasoning ?? false}
|
||||
onCheckedChange={(checked) => updateSettings({ showReasoning: checked })}
|
||||
/>
|
||||
</div>
|
||||
{!preferences?.simpleChatMode && (
|
||||
<>
|
||||
<div className="flex flex-row items-center justify-between rounded-lg border border-border p-4">
|
||||
<div className="space-y-0.5">
|
||||
<Label htmlFor="showReasoning" className="text-base">Show reasoning</Label>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Display model reasoning and thought process
|
||||
</p>
|
||||
</div>
|
||||
<Switch
|
||||
id="showReasoning"
|
||||
checked={preferences?.showReasoning ?? false}
|
||||
onCheckedChange={(checked) => updateSettings({ showReasoning: checked })}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-row items-center justify-between rounded-lg border border-border p-4">
|
||||
<div className="space-y-0.5">
|
||||
<Label htmlFor="expandToolCalls" className="text-base">Expand tool calls</Label>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Automatically expand tool call details by default
|
||||
</p>
|
||||
</div>
|
||||
<Switch
|
||||
id="expandToolCalls"
|
||||
checked={preferences?.expandToolCalls ?? false}
|
||||
onCheckedChange={(checked) => updateSettings({ expandToolCalls: checked })}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex flex-row items-center justify-between rounded-lg border border-border p-4">
|
||||
<div className="space-y-0.5">
|
||||
<Label htmlFor="expandToolCalls" className="text-base">Expand tool calls</Label>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Automatically expand tool call details by default
|
||||
</p>
|
||||
</div>
|
||||
<Switch
|
||||
id="expandToolCalls"
|
||||
checked={preferences?.expandToolCalls ?? false}
|
||||
onCheckedChange={(checked) => updateSettings({ expandToolCalls: checked })}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-row items-center justify-between rounded-lg border border-border p-4">
|
||||
<div className="space-y-0.5">
|
||||
<Label htmlFor="expandDiffs" className="text-base">Expand diffs</Label>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Show file diffs expanded by default for edit operations
|
||||
</p>
|
||||
</div>
|
||||
<Switch
|
||||
id="expandDiffs"
|
||||
checked={preferences?.expandDiffs ?? true}
|
||||
onCheckedChange={(checked) => updateSettings({ expandDiffs: checked })}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex flex-row items-center justify-between rounded-lg border border-border p-4">
|
||||
<div className="space-y-0.5">
|
||||
<Label htmlFor="expandDiffs" className="text-base">Expand diffs</Label>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Show file diffs expanded by default for edit operations
|
||||
</p>
|
||||
</div>
|
||||
<Switch
|
||||
id="expandDiffs"
|
||||
checked={preferences?.expandDiffs ?? true}
|
||||
onCheckedChange={(checked) => updateSettings({ expandDiffs: checked })}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
import { memo, useEffect, useState } from 'react'
|
||||
import { useSessionStatusForSession, type SessionStatusType } from '@/stores/sessionStatusStore'
|
||||
|
||||
interface MiniScannerProps {
|
||||
sessionID: string
|
||||
className?: string
|
||||
}
|
||||
|
||||
const SCANNER_WIDTH = 6
|
||||
const SCANNER_SEGMENTS = 12
|
||||
|
||||
export const MiniScanner = memo(function MiniScanner({
|
||||
sessionID,
|
||||
className = ''
|
||||
}: MiniScannerProps) {
|
||||
const status = useSessionStatusForSession(sessionID)
|
||||
const [position, setPosition] = useState(0)
|
||||
const [direction, setDirection] = useState(1)
|
||||
|
||||
useEffect(() => {
|
||||
if (status.type !== 'busy' && status.type !== 'retry' && status.type !== 'compact') {
|
||||
return
|
||||
}
|
||||
|
||||
const interval = setInterval(() => {
|
||||
setPosition(prev => {
|
||||
const next = prev + direction
|
||||
if (next >= SCANNER_SEGMENTS - SCANNER_WIDTH) {
|
||||
setDirection(-1)
|
||||
return SCANNER_SEGMENTS - SCANNER_WIDTH
|
||||
}
|
||||
if (next <= 0) {
|
||||
setDirection(1)
|
||||
return 0
|
||||
}
|
||||
return next
|
||||
})
|
||||
}, 60)
|
||||
|
||||
return () => clearInterval(interval)
|
||||
}, [status.type, direction])
|
||||
|
||||
const getSegmentColor = (index: number, statusType: SessionStatusType['type']) => {
|
||||
if (statusType === 'idle') {
|
||||
return 'bg-transparent'
|
||||
}
|
||||
|
||||
const distance = Math.abs(index - (position + SCANNER_WIDTH / 2))
|
||||
const maxDistance = SCANNER_WIDTH / 2
|
||||
|
||||
if (distance > maxDistance + 1) {
|
||||
return 'bg-muted/20'
|
||||
}
|
||||
|
||||
const intensity = Math.max(0, 1 - distance / (maxDistance + 2))
|
||||
|
||||
if (statusType === 'retry') {
|
||||
if (intensity > 0.8) return 'bg-amber-500'
|
||||
if (intensity > 0.5) return 'bg-amber-500/70'
|
||||
if (intensity > 0.2) return 'bg-amber-500/40'
|
||||
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'
|
||||
return 'bg-blue-500/20'
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={`flex items-center ${className}`}>
|
||||
<div className="flex gap-0.5">
|
||||
{Array.from({ length: SCANNER_SEGMENTS }).map((_, i) => (
|
||||
<div
|
||||
key={i}
|
||||
className={`w-0.5 h-2 rounded-sm transition-colors duration-75 ${getSegmentColor(i, status.type)}`}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})
|
||||
@@ -4,6 +4,8 @@ import { useSessionStatusForSession, type SessionStatusType } from '@/stores/ses
|
||||
interface SessionStatusIndicatorProps {
|
||||
sessionID: string
|
||||
className?: string
|
||||
size?: 'sm' | 'md'
|
||||
showLabel?: boolean
|
||||
}
|
||||
|
||||
const SCANNER_WIDTH = 6
|
||||
@@ -11,7 +13,9 @@ const SCANNER_SEGMENTS = 12
|
||||
|
||||
export const SessionStatusIndicator = memo(function SessionStatusIndicator({
|
||||
sessionID,
|
||||
className = ''
|
||||
className = '',
|
||||
size = 'md',
|
||||
showLabel = false
|
||||
}: SessionStatusIndicatorProps) {
|
||||
const status = useSessionStatusForSession(sessionID)
|
||||
const [position, setPosition] = useState(0)
|
||||
@@ -42,7 +46,7 @@ export const SessionStatusIndicator = memo(function SessionStatusIndicator({
|
||||
}, [status.type, direction])
|
||||
|
||||
useEffect(() => {
|
||||
if (status.type !== 'retry') {
|
||||
if (!showLabel || status.type !== 'retry') {
|
||||
setRetryCountdown(0)
|
||||
return
|
||||
}
|
||||
@@ -56,7 +60,7 @@ export const SessionStatusIndicator = memo(function SessionStatusIndicator({
|
||||
}, 1000)
|
||||
|
||||
return () => clearInterval(interval)
|
||||
}, [status])
|
||||
}, [status, showLabel])
|
||||
|
||||
if (status.type === 'idle') {
|
||||
return null
|
||||
@@ -92,63 +96,25 @@ export const SessionStatusIndicator = memo(function SessionStatusIndicator({
|
||||
return 'bg-blue-500/20'
|
||||
}
|
||||
|
||||
const segmentClass = size === 'sm' ? 'w-0.5 h-2' : 'w-1 h-4'
|
||||
const containerGap = showLabel ? 'gap-2' : ''
|
||||
|
||||
return (
|
||||
<div className={`flex items-center gap-2 ${className}`}>
|
||||
<div className={`flex items-center ${containerGap} ${className}`}>
|
||||
<div className="flex gap-0.5">
|
||||
{Array.from({ length: SCANNER_SEGMENTS }).map((_, i) => (
|
||||
<div
|
||||
key={i}
|
||||
className={`w-1 h-4 rounded-sm transition-colors duration-75 ${getSegmentColor(i, status.type)}`}
|
||||
className={`${segmentClass} rounded-sm transition-colors duration-75 ${getSegmentColor(i, status.type)}`}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{status.type === 'retry' && (
|
||||
<>
|
||||
Retry #{status.attempt}
|
||||
{retryCountdown > 0 && <span className="text-amber-500 ml-1">({retryCountdown}s)</span>}
|
||||
</>
|
||||
)}
|
||||
</span>
|
||||
{showLabel && status.type === 'retry' && (
|
||||
<span className="text-xs text-muted-foreground">
|
||||
Retry #{status.attempt}
|
||||
{retryCountdown > 0 && <span className="text-amber-500 ml-1">({retryCountdown}s)</span>}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
})
|
||||
|
||||
interface CompactStatusIndicatorProps {
|
||||
sessionID: string
|
||||
className?: string
|
||||
}
|
||||
|
||||
export const CompactStatusIndicator = memo(function CompactStatusIndicator({
|
||||
sessionID,
|
||||
className = ''
|
||||
}: CompactStatusIndicatorProps) {
|
||||
const status = useSessionStatusForSession(sessionID)
|
||||
const [frame, setFrame] = useState(0)
|
||||
|
||||
useEffect(() => {
|
||||
if (status.type !== 'busy' && status.type !== 'retry' && status.type !== 'compact') return
|
||||
|
||||
const interval = setInterval(() => {
|
||||
setFrame(prev => (prev + 1) % 8)
|
||||
}, 120)
|
||||
|
||||
return () => clearInterval(interval)
|
||||
}, [status.type])
|
||||
|
||||
if (status.type === 'idle') {
|
||||
return null
|
||||
}
|
||||
|
||||
const pulseFrames = ['●', '◐', '○', '◑', '●', '◐', '○', '◑']
|
||||
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}` : status.type === 'compact' ? 'Compacting' : 'Working'}
|
||||
</span>
|
||||
</span>
|
||||
)
|
||||
})
|
||||
@@ -331,23 +331,22 @@ export const useSendPrompt = (opcodeUrl: string | null | undefined, directory?:
|
||||
},
|
||||
onSuccess: async (data, variables) => {
|
||||
const { sessionID } = variables;
|
||||
const { optimisticUserID, response } = data;
|
||||
const { response } = data;
|
||||
const messagesQueryKey = ["opencode", "messages", opcodeUrl, sessionID, directory];
|
||||
|
||||
queryClient.setQueryData<MessageWithParts[]>(
|
||||
messagesQueryKey,
|
||||
(old) => {
|
||||
if (!old) return old;
|
||||
const withoutOptimistic = old.filter((msgWithParts) => msgWithParts.info.id !== optimisticUserID);
|
||||
|
||||
const existingIdx = withoutOptimistic.findIndex(m => m.info.id === response.info.id);
|
||||
|
||||
const existingIdx = old.findIndex(m => m.info.id === response.info.id);
|
||||
if (existingIdx >= 0) {
|
||||
const updated = [...withoutOptimistic];
|
||||
const updated = [...old];
|
||||
updated[existingIdx] = { info: response.info, parts: response.parts };
|
||||
return updated;
|
||||
}
|
||||
|
||||
return [...withoutOptimistic, { info: response.info, parts: response.parts }];
|
||||
|
||||
return [...old, { info: response.info, parts: response.parts }];
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -114,9 +114,10 @@ export const UserPreferencesSchema = z.object({
|
||||
defaultModel: z.string().optional(),
|
||||
defaultAgent: z.string().optional(),
|
||||
autoScroll: z.boolean(),
|
||||
showReasoning: z.boolean(),
|
||||
expandToolCalls: z.boolean(),
|
||||
expandDiffs: z.boolean(),
|
||||
expandToolCalls: z.boolean(),
|
||||
showReasoning: z.boolean(),
|
||||
simpleChatMode: z.boolean(),
|
||||
leaderKey: z.string().optional(),
|
||||
directShortcuts: z.array(z.string()).optional(),
|
||||
keyboardShortcuts: z.record(z.string(), z.string()),
|
||||
@@ -161,9 +162,10 @@ export const DEFAULT_USER_PREFERENCES = {
|
||||
theme: "dark" as const,
|
||||
mode: "build" as const,
|
||||
autoScroll: true,
|
||||
showReasoning: false,
|
||||
expandToolCalls: false,
|
||||
expandDiffs: true,
|
||||
expandToolCalls: false,
|
||||
showReasoning: false,
|
||||
simpleChatMode: false,
|
||||
leaderKey: DEFAULT_LEADER_KEY,
|
||||
directShortcuts: ['submit', 'abort'],
|
||||
keyboardShortcuts: DEFAULT_KEYBOARD_SHORTCUTS,
|
||||
|
||||
Reference in new issue
Block a user