Skip to content

Commit

Permalink
fix: properly handle object type parameters in tools
Browse files Browse the repository at this point in the history
- 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>
  • Loading branch information
devin-ai-integration[bot] and ashwin-ant committed Dec 13, 2024
1 parent eb70539 commit 1f4d35f
Showing 1 changed file with 41 additions and 8 deletions.
49 changes: 41 additions & 8 deletions client/src/components/ToolsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -174,19 +176,50 @@ const ToolsTab = ({
}
className="mt-1"
/>
) :
// @ts-expect-error Tool schema types are not fully typed
value.type === "object" ? (
<Textarea
id={key}
name={key}
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
// @ts-expect-error value type is currently unknown
type={value.type === "number" ? "number" : "text"}
type={
// @ts-expect-error Tool schema types are not fully typed
value.type === "number" ? "number" : "text"
}
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,
[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,
Expand Down

0 comments on commit 1f4d35f

Please sign in to comment.