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:
@@ -159,13 +159,15 @@ const ToolsTab = ({
|
|||||||
{key}
|
{key}
|
||||||
</Label>
|
</Label>
|
||||||
{
|
{
|
||||||
/* @ts-expect-error value type is currently unknown */
|
// @ts-expect-error Tool schema types are not fully typed
|
||||||
value.type === "string" ? (
|
value.type === "string" ? (
|
||||||
<Textarea
|
<Textarea
|
||||||
id={key}
|
id={key}
|
||||||
name={key}
|
name={key}
|
||||||
// @ts-expect-error value type is currently unknown
|
placeholder={
|
||||||
placeholder={value.description}
|
// @ts-expect-error Tool schema types are not fully typed
|
||||||
|
value.description
|
||||||
|
}
|
||||||
onChange={(e) =>
|
onChange={(e) =>
|
||||||
setParams({
|
setParams({
|
||||||
...params,
|
...params,
|
||||||
@@ -174,19 +176,50 @@ const ToolsTab = ({
|
|||||||
}
|
}
|
||||||
className="mt-1"
|
className="mt-1"
|
||||||
/>
|
/>
|
||||||
) : (
|
) :
|
||||||
<Input
|
// @ts-expect-error Tool schema types are not fully typed
|
||||||
// @ts-expect-error value type is currently unknown
|
value.type === "object" ? (
|
||||||
type={value.type === "number" ? "number" : "text"}
|
<Textarea
|
||||||
id={key}
|
id={key}
|
||||||
name={key}
|
name={key}
|
||||||
// @ts-expect-error value type is currently unknown
|
placeholder={
|
||||||
placeholder={value.description}
|
// @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) =>
|
onChange={(e) =>
|
||||||
setParams({
|
setParams({
|
||||||
...params,
|
...params,
|
||||||
[key]:
|
[key]:
|
||||||
// @ts-expect-error value type is currently unknown
|
// @ts-expect-error Tool schema types are not fully typed
|
||||||
value.type === "number"
|
value.type === "number"
|
||||||
? Number(e.target.value)
|
? Number(e.target.value)
|
||||||
: e.target.value,
|
: e.target.value,
|
||||||
|
|||||||
Reference in New Issue
Block a user