Skip to content

Commit bdcdc02

Browse files
committed
refactor: move components into folders
1 parent c687f70 commit bdcdc02

21 files changed

+53
-57
lines changed

cli/src/chat.tsx

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,28 @@
11
import { useRenderer } from '@opentui/react'
2-
import React, {
3-
useCallback,
4-
useEffect,
5-
useMemo,
6-
useRef,
7-
useState,
8-
} from 'react'
9-
10-
11-
import { logger } from './logger'
12-
import { buildMessageTree } from './message-tree-utils'
13-
import { MultilineInput } from './multiline-input'
14-
import { Separator } from './separator'
15-
import { StatusIndicator, useHasStatus } from './status-indicator'
2+
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
3+
4+
import { MultilineInput } from './components/multiline-input'
5+
import { Separator } from './components/separator'
6+
import { StatusIndicator, useHasStatus } from './components/status-indicator'
7+
import { useClipboard } from './hooks/use-clipboard'
8+
import { useInputHistory } from './hooks/use-input-history'
9+
import { useKeyboardHandlers } from './hooks/use-keyboard-handlers'
10+
import { useMessageQueue } from './hooks/use-message-queue'
11+
import { useMessageRenderer } from './hooks/use-message-renderer'
12+
import { useScrollManagement } from './hooks/use-scroll-management'
13+
import { useSendMessage } from './hooks/use-send-message'
14+
import { formatTimestamp, formatQueuedPreview } from './utils/helpers'
15+
import { logger } from './utils/logger'
16+
import { buildMessageTree } from './utils/message-tree-utils'
1617
import {
1718
type ThemeName,
1819
chatThemes,
1920
createMarkdownPalette,
2021
detectSystemTheme,
21-
} from './theme-system'
22-
import { useClipboard } from './use-clipboard'
23-
import { useInputHistory } from './use-input-history'
24-
import { useKeyboardHandlers } from './use-keyboard-handlers'
25-
import { useMessageQueue } from './use-message-queue'
26-
import { useMessageRenderer } from './use-message-renderer'
27-
import { useScrollManagement } from './use-scroll-management'
28-
import { useSendMessage } from './use-send-message'
29-
import { formatTimestamp, formatQueuedPreview } from './utils'
22+
} from './utils/theme-system'
3023

3124
import type { ToolName } from '@codebuff/sdk'
32-
import type {
33-
InputRenderable,
34-
ScrollBoxRenderable,
35-
} from '@opentui/core'
25+
import type { InputRenderable, ScrollBoxRenderable } from '@opentui/core'
3626

3727
type ChatVariant = 'ai' | 'user' | 'agent'
3828

@@ -117,10 +107,6 @@ export const App = ({ initialPrompt }: { initialPrompt?: string } = {}) => {
117107
renderer?.setBackgroundColor(theme.background)
118108
}, [renderer, theme.background])
119109

120-
121-
122-
123-
124110
const abortControllerRef = useRef<AbortController | null>(null)
125111

126112
const registerAgentRef = useCallback((agentId: string, element: any) => {
@@ -142,7 +128,8 @@ export const App = ({ initialPrompt }: { initialPrompt?: string } = {}) => {
142128
setInputValue,
143129
)
144130

145-
const sendMessageRef = useRef<(content: string, onComplete?: () => void) => Promise<void>>()
131+
const sendMessageRef =
132+
useRef<(content: string, onComplete?: () => void) => Promise<void>>()
146133

147134
const {
148135
queuedMessages,
@@ -260,7 +247,15 @@ export const App = ({ initialPrompt }: { initialPrompt?: string } = {}) => {
260247
}
261248

262249
sendMessage(trimmed)
263-
}, [inputValue, isStreaming, sendMessage, saveToHistory, addToQueue, streamMessageIdRef, isChainInProgressRef])
250+
}, [
251+
inputValue,
252+
isStreaming,
253+
sendMessage,
254+
saveToHistory,
255+
addToQueue,
256+
streamMessageIdRef,
257+
isChainInProgressRef,
258+
])
264259

265260
const handleThemeToggle = useCallback(() => {
266261
setThemeName((prev) => (prev === 'dark' ? 'light' : 'dark'))
@@ -372,11 +367,12 @@ export const App = ({ initialPrompt }: { initialPrompt?: string } = {}) => {
372367
/>
373368
{hasStatus && queuedMessages.length > 0 && ' '}
374369
{queuedMessages.length > 0 && (
375-
<span
376-
fg={theme.statusSecondary}
377-
bg={theme.inputFocusedBg}
378-
>
379-
{' '}{formatQueuedPreview(queuedMessages, Math.max(30, renderer.width - 25))}{' '}
370+
<span fg={theme.statusSecondary} bg={theme.inputFocusedBg}>
371+
{' '}
372+
{formatQueuedPreview(
373+
queuedMessages,
374+
Math.max(30, renderer.width - 25),
375+
)}{' '}
380376
</span>
381377
)}
382378
</text>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { TextAttributes } from '@opentui/core'
22
import React, { type ReactNode } from 'react'
33

4-
import type { ChatTheme } from './theme-system'
4+
import type { ChatTheme } from '../utils/theme-system'
55

66
interface BranchItemProps {
77
name: string
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ import { TextAttributes } from '@opentui/core'
22
import React, { type ReactNode } from 'react'
33

44
import { BranchItem } from './branch-item'
5-
import { getToolDisplayInfo } from './codebuff-client'
5+
import { getToolDisplayInfo } from '../utils/codebuff-client'
66
import {
77
renderMarkdown,
88
renderStreamingMarkdown,
99
hasMarkdown,
1010
type MarkdownPalette,
11-
} from './markdown-renderer'
11+
} from '../utils/markdown-renderer'
1212

13-
import type { ContentBlock } from './chat'
14-
import type { ChatTheme } from './theme-system'
13+
import type { ContentBlock } from '../chat'
14+
import type { ChatTheme } from '../utils/theme-system'
1515

1616
interface MessageBlockProps {
1717
messageId: string
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react'
22

3-
import type { ChatTheme } from './theme-system'
3+
import type { ChatTheme } from '../utils/theme-system'
44

55
interface SeparatorProps {
66
theme: ChatTheme
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React, { useEffect, useState } from 'react'
22

3-
import { getCodebuffClient } from './codebuff-client'
43
import { ShimmerText } from './shimmer-text'
4+
import { getCodebuffClient } from '../utils/codebuff-client'
55

6-
import type { ChatTheme } from './theme-system'
6+
import type { ChatTheme } from '../utils/theme-system'
77

88
const THINKING_SHIMMER_COLORS = [
99
'#9ca3af',
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useRenderer } from '@opentui/react'
22
import { useCallback, useEffect, useRef, useState } from 'react'
33

4-
import { logger } from './logger'
4+
import { logger } from '../utils/logger'
55

66
export const useClipboard = () => {
77
const renderer = useRenderer()

0 commit comments

Comments
 (0)