This repository was archived by the owner on May 15, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Expand file tree
/
Copy pathCustomToolsSettings.tsx
More file actions
173 lines (155 loc) · 5.31 KB
/
Copy pathCustomToolsSettings.tsx
File metadata and controls
173 lines (155 loc) · 5.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import { useState, useEffect, useCallback, useMemo } from "react"
import { useEvent } from "react-use"
import { VSCodeCheckbox } from "@vscode/webview-ui-toolkit/react"
import { RefreshCw, Loader2 } from "lucide-react"
import type { SerializedCustomToolDefinition } from "@roo-code/types"
import { useAppTranslation } from "@/i18n/TranslationContext"
import { vscode } from "@/utils/vscode"
import { Button } from "@/components/ui"
interface ToolParameter {
name: string
type: string
description?: string
required: boolean
}
interface ProcessedTool {
name: string
description: string
parameters: ToolParameter[]
}
interface CustomToolsSettingsProps {
enabled: boolean
onChange: (enabled: boolean) => void
}
export const CustomToolsSettings = ({ enabled, onChange }: CustomToolsSettingsProps) => {
const { t } = useAppTranslation()
const [tools, setTools] = useState<SerializedCustomToolDefinition[]>([])
const [isRefreshing, setIsRefreshing] = useState(false)
const [refreshError, setRefreshError] = useState<string | null>(null)
useEffect(() => {
if (enabled) {
vscode.postMessage({ type: "refreshCustomTools" })
} else {
setTools([])
}
}, [enabled])
useEvent("message", (event: MessageEvent) => {
const message = event.data
if (message.type === "customToolsResult") {
setTools(message.tools || [])
setIsRefreshing(false)
setRefreshError(message.error ?? null)
}
})
const onRefresh = useCallback(() => {
setIsRefreshing(true)
setRefreshError(null)
vscode.postMessage({ type: "refreshCustomTools" })
}, [])
const processedTools = useMemo<ProcessedTool[]>(
() =>
tools.map((tool) => {
const params = tool.parameters
const properties = (params?.properties ?? {}) as Record<string, { type?: string; description?: string }>
const required = (params?.required as string[] | undefined) ?? []
return {
name: tool.name,
description: tool.description,
parameters: Object.entries(properties).map(([name, def]) => ({
name,
type: def.type ?? "any",
description: def.description,
required: required.includes(name),
})),
}
}),
[tools],
)
return (
<div className="space-y-4">
<div>
<div className="flex items-center gap-2">
<VSCodeCheckbox checked={enabled} onChange={(e: any) => onChange(e.target.checked)}>
<span className="font-medium">{t("settings:experimental.CUSTOM_TOOLS.name")}</span>
</VSCodeCheckbox>
</div>
<p className="text-vscode-descriptionForeground text-sm mt-0">
{t("settings:experimental.CUSTOM_TOOLS.description")}
</p>
</div>
{enabled && (
<div className="ml-2 space-y-3">
<div className="flex items-center justify-between gap-4">
<label className="block font-medium">
{t("settings:experimental.CUSTOM_TOOLS.toolsHeader")}
</label>
<Button variant="outline" onClick={onRefresh} disabled={isRefreshing}>
<div className="flex items-center gap-2">
{isRefreshing ? (
<Loader2 className="w-4 h-4 animate-spin" />
) : (
<RefreshCw className="w-4 h-4" />
)}
{isRefreshing
? t("settings:experimental.CUSTOM_TOOLS.refreshing")
: t("settings:experimental.CUSTOM_TOOLS.refreshButton")}
</div>
</Button>
</div>
{refreshError && (
<div className="p-2 bg-vscode-inputValidation-errorBackground text-vscode-errorForeground rounded text-sm border border-vscode-inputValidation-errorBorder">
{t("settings:experimental.CUSTOM_TOOLS.refreshError")}: {refreshError}
</div>
)}
{processedTools.length === 0 ? (
<p className="text-vscode-descriptionForeground text-sm italic">
{t("settings:experimental.CUSTOM_TOOLS.noTools")}
</p>
) : (
<div className="space-y-2">
{processedTools.map((tool) => (
<div
key={tool.name}
className="p-3 bg-vscode-editor-background border border-vscode-panel-border rounded">
<div className="font-medium text-vscode-foreground">{tool.name}</div>
<p className="text-vscode-descriptionForeground text-sm mt-1">{tool.description}</p>
{tool.parameters.length > 0 && (
<div className="mt-3">
<div className="text-xs font-medium text-vscode-foreground mb-2">
{t("settings:experimental.CUSTOM_TOOLS.toolParameters")}:
</div>
<div className="space-y-1">
{tool.parameters.map((param) => (
<div
key={param.name}
className="flex items-start gap-2 text-xs pl-2 py-1 border-l-2 border-vscode-panel-border">
<code className="text-vscode-textLink-foreground font-mono">
{param.name}
</code>
<span className="text-vscode-descriptionForeground">
({param.type})
</span>
{param.required && (
<span className="text-vscode-errorForeground text-[10px] uppercase">
required
</span>
)}
{param.description && (
<span className="text-vscode-descriptionForeground">
— {param.description}
</span>
)}
</div>
))}
</div>
</div>
)}
</div>
))}
</div>
)}
</div>
)}
</div>
)
}