fix: properly handle object type parameters in tools

- Add special handling for object type parameters
- Parse JSON input for object parameters
- Maintain raw input if JSON parsing fails
- Fixes #110

Co-Authored-By: ashwin@anthropic.com <ashwin@anthropic.com>
This commit is contained in:
Devin AI
2024-12-13 11:21:35 +00:00
parent eb70539958
commit 1f4d35f8a3

View File

@@ -159,13 +159,15 @@ const ToolsTab = ({
{key}
</Label>
{
/* @ts-expect-error value type is currently unknown */
// @ts-expect-error Tool schema types are not fully typed
value.type === "string" ? (
<Textarea
id={key}
name={key}
// @ts-expect-error value type is currently unknown
placeholder={value.description}
placeholder={
// @ts-expect-error Tool schema types are not fully typed
value.description
}
onChange={(e) =>
setParams({
...params,
@@ -174,19 +176,50 @@ const ToolsTab = ({
}
className="mt-1"
/>
) : (
<Input
// @ts-expect-error value type is currently unknown
type={value.type === "number" ? "number" : "text"}
) :
// @ts-expect-error Tool schema types are not fully typed
value.type === "object" ? (
<Textarea
id={key}
name={key}
// @ts-expect-error value type is currently unknown
placeholder={value.description}
placeholder={
// @ts-expect-error Tool schema types are not fully typed
value.description
}
onChange={(e) => {
try {
const parsed = JSON.parse(e.target.value);
setParams({
...params,
[key]: parsed,
});
} catch (err) {
// If invalid JSON, store as string - will be validated on submit
setParams({
...params,
[key]: e.target.value,
});
}
}}
className="mt-1"
/>
) : (
<Input
type={
// @ts-expect-error Tool schema types are not fully typed
value.type === "number" ? "number" : "text"
}
id={key}
name={key}
placeholder={
// @ts-expect-error Tool schema types are not fully typed
value.description
}
onChange={(e) =>
setParams({
...params,
[key]:
// @ts-expect-error value type is currently unknown
// @ts-expect-error Tool schema types are not fully typed
value.type === "number"
? Number(e.target.value)
: e.target.value,