Skip to content

Commit eaded28

Browse files
committed
Fix types (tool components cannot return null anymore)
1 parent 246eb10 commit eaded28

File tree

9 files changed

+24
-31
lines changed

9 files changed

+24
-31
lines changed

cli/src/components/tools/code-search.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type { ToolRenderConfig } from './types'
1313
export const CodeSearchComponent = defineToolComponent({
1414
toolName: 'code_search',
1515

16-
render(toolBlock, theme, options): ToolRenderConfig | null {
16+
render(toolBlock, theme, options): ToolRenderConfig {
1717
const input = toolBlock.input as any
1818
const pattern = input?.pattern ?? ''
1919
const flags = input?.flags ?? ''

cli/src/components/tools/glob.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type { ToolRenderConfig } from './types'
1111
export const GlobComponent = defineToolComponent({
1212
toolName: 'glob',
1313

14-
render(toolBlock, theme, options): ToolRenderConfig | null {
14+
render(toolBlock, theme, options): ToolRenderConfig {
1515
const input = toolBlock.input as any
1616
const pattern = input?.pattern ?? ''
1717
const cwd = input?.cwd ?? ''
@@ -39,7 +39,7 @@ export const GlobComponent = defineToolComponent({
3939
}
4040

4141
if (!pattern) {
42-
return null
42+
return { content: null }
4343
}
4444

4545
// Build single-line summary

cli/src/components/tools/list-directory.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type { ToolRenderConfig } from './types'
1313
export const ListDirectoryComponent = defineToolComponent({
1414
toolName: 'list_directory',
1515

16-
render(toolBlock, theme, options): ToolRenderConfig | null {
16+
render(toolBlock, theme, options): ToolRenderConfig {
1717
const input = toolBlock.input as any
1818

1919
// Extract directories from input
@@ -35,19 +35,14 @@ export const ListDirectoryComponent = defineToolComponent({
3535
}
3636

3737
if (directories.length === 0) {
38-
return null
38+
return { content: null }
3939
}
4040

4141
// Format directory list
4242
const description = directories.join(', ')
4343

4444
return {
45-
content: (
46-
<SimpleToolCallItem
47-
name="List"
48-
description={description}
49-
/>
50-
),
45+
content: <SimpleToolCallItem name="List" description={description} />,
5146
}
5247
},
5348
})

cli/src/components/tools/read-files.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { TextAttributes } from '@opentui/core'
22

3-
import { useTheme } from '../../hooks/use-theme'
43
import { defineToolComponent } from './types'
4+
import { useTheme } from '../../hooks/use-theme'
55

66
import type { ToolRenderConfig } from './types'
77

@@ -47,7 +47,7 @@ const ReadFilesSimpleToolCallItem = ({
4747
export const ReadFilesComponent = defineToolComponent({
4848
toolName: 'read_files',
4949

50-
render(toolBlock, theme, options): ToolRenderConfig | null {
50+
render(toolBlock, theme, options): ToolRenderConfig {
5151
const input = toolBlock.input as any
5252

5353
// Extract file paths from input
@@ -60,7 +60,7 @@ export const ReadFilesComponent = defineToolComponent({
6060
}
6161

6262
if (filePaths.length === 0) {
63-
return null
63+
return { content: null }
6464
}
6565

6666
return {

cli/src/components/tools/read-subtree.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import { SimpleToolCallItem } from './tool-call-item'
12
import { defineToolComponent } from './types'
23

34
import type { ToolRenderConfig } from './types'
4-
import { SimpleToolCallItem } from './tool-call-item'
55

66
/**
77
* UI component for read_subtree tool.
@@ -11,7 +11,7 @@ import { SimpleToolCallItem } from './tool-call-item'
1111
export const ReadSubtreeComponent = defineToolComponent({
1212
toolName: 'read_subtree',
1313

14-
render(toolBlock, theme, options): ToolRenderConfig | null {
14+
render(toolBlock, theme, options): ToolRenderConfig {
1515
const input = toolBlock.input as any
1616
const paths: string[] = Array.isArray(input?.paths)
1717
? input.paths.filter((p: any) => typeof p === 'string' && p.trim().length)

cli/src/components/tools/run-terminal-command.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { TextAttributes } from '@opentui/core'
22
import { useState } from 'react'
33

44
import { defineToolComponent } from './types'
5-
import { useTheme } from '../../hooks/use-theme'
6-
import { Button } from '../button'
75
import { useTerminalDimensions } from '../../hooks/use-terminal-dimensions'
6+
import { useTheme } from '../../hooks/use-theme'
87
import { getLastNVisualLines } from '../../utils/text-layout'
8+
import { Button } from '../button'
99

1010
import type { ToolRenderConfig } from './types'
1111

@@ -17,17 +17,13 @@ import type { ToolRenderConfig } from './types'
1717
export const RunTerminalCommandComponent = defineToolComponent({
1818
toolName: 'run_terminal_command',
1919

20-
render(toolBlock, theme): ToolRenderConfig | null {
20+
render(toolBlock, theme): ToolRenderConfig {
2121
// Extract command from input
2222
const command =
2323
toolBlock.input && typeof (toolBlock.input as any).command === 'string'
2424
? (toolBlock.input as any).command.trim()
2525
: null
2626

27-
if (!command) {
28-
return null
29-
}
30-
3127
// Extract output if available
3228
const output = toolBlock.output ? toolBlock.output.trim() : null
3329

cli/src/components/tools/str-replace.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { TextAttributes } from '@opentui/core'
22

3-
import { useTheme } from '../../hooks/use-theme'
4-
import { defineToolComponent } from './types'
53
import { DiffViewer } from './diff-viewer'
4+
import { defineToolComponent } from './types'
5+
import { useTheme } from '../../hooks/use-theme'
66

77
import type { ToolRenderConfig } from './types'
88

@@ -82,7 +82,7 @@ const EditBody = ({ name, filePath, diffText }: EditBodyProps) => {
8282
export const StrReplaceComponent = defineToolComponent({
8383
toolName: 'str_replace',
8484

85-
render(toolBlock, _theme, options): ToolRenderConfig | null {
85+
render(toolBlock, _theme, options): ToolRenderConfig {
8686
const outputStr =
8787
typeof toolBlock.output === 'string' ? toolBlock.output : ''
8888
const diff =

cli/src/components/tools/write-file.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
import { StrReplaceComponent } from './str-replace'
12
import { defineToolComponent } from './types'
3+
24
import type { ToolRenderConfig } from './types'
3-
import { StrReplaceComponent } from './str-replace'
45

56
// Reuse the extraction and rendering logic from str-replace by delegating
67

78
export const WriteFileComponent = defineToolComponent({
89
toolName: 'write_file',
910

10-
render(toolBlock, theme, options): ToolRenderConfig | null {
11+
render(toolBlock, theme, options): ToolRenderConfig {
1112
// Call the str_replace renderer with the same block shape
1213
// since both tools share identical UI and output structure.
1314
return StrReplaceComponent.render(toolBlock as any, theme, options)

cli/src/components/tools/write-todos.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { TextAttributes } from '@opentui/core'
22

3-
import { useTheme } from '../../hooks/use-theme'
43
import { defineToolComponent } from './types'
4+
import { useTheme } from '../../hooks/use-theme'
5+
56
import type { ToolRenderConfig } from './types'
67

78
interface WriteTodosItemProps {
@@ -68,7 +69,7 @@ const WriteTodosItem = ({ todos }: WriteTodosItemProps) => {
6869
export const WriteTodosComponent = defineToolComponent({
6970
toolName: 'write_todos',
7071

71-
render(toolBlock, theme, options): ToolRenderConfig | null {
72+
render(toolBlock, theme, options): ToolRenderConfig {
7273
const { input } = toolBlock
7374

7475
// Extract todos from input
@@ -84,7 +85,7 @@ export const WriteTodosComponent = defineToolComponent({
8485
}
8586

8687
if (todos.length === 0) {
87-
return null
88+
return { content: null }
8889
}
8990

9091
return {

0 commit comments

Comments
 (0)