import { Fragment, useMemo, useState } from "react";
import type { Capture, Json } from "../model.js";
import { Copy, Data } from "./components.js";
import { output } from "./format.js";
import { parseSchema, type SchemaNode, type ToolDoc, toolDocuments } from "./tool-schema.js";
function DocumentationText({ value }: { value: string }) {
const parts = useMemo(() => {
const parts: { id: string; text: string; code: boolean }[] = [];
let offset = 0;
for (const match of value.matchAll(/^```[^\n]*\n([\s\S]*?)^```[ \t]*(?:\n|$)/gm)) {
parts.push({ id: `text-${offset}`, text: value.slice(offset, match.index), code: false });
parts.push({ id: `code-${match.index}`, text: match[1] ?? "", code: true });
offset = match.index + match[0].length;
}
parts.push({ id: `text-${offset}`, text: value.slice(offset), code: false });
return parts;
}, [value]);
return parts.map((part) =>
part.code ? (
{part.text}
) : (
{part.text}
),
);
}
function SchemaRows({
node,
depth = 0,
expansion,
}: {
node: SchemaNode;
depth?: number;
expansion?: Map;
}) {
const [open, setOpen] = useState(() => expansion?.get(node.id) ?? false);
return (
|
{node.children.length ? (
) : (
node.name
)}
|
{node.type}
|
{node.required === undefined ? "—" : node.required === "unknown" ? "Unknown" : node.required ? "Yes" : "No"}
|
{node.description && {node.description} }
{node.annotations.map(([key, value]) => (
{key}:
{JSON.stringify(value)}
))}
{node.limited && (
Documentation limit reached; inspect Raw JSON for the complete captured schema.
)}
|
{open &&
node.children.map((child) => (
))}
);
}
export function ParameterSchema({ value, expansion }: { value: Json; expansion?: Map }) {
const root = useMemo(() => parseSchema(value), [value]);
return (
Input parameters
| Parameter |
Type |
Required |
Description / constraints |
{root.children.map((node) => (
))}
);
}
function ToolDetails({ tool, scope, truncated }: { tool: ToolDoc; scope: string; truncated: boolean }) {
const [mode, setMode] = useState("documentation");
return (
{tool.name}
{["documentation", "raw"].map((value) => (
))}
{mode === "raw" ? (
) : (
<>
{tool.description ? (
) : (
No description supplied.
)}
{tool.parameters === undefined ? (
Input schema unspecified.
) : (
)}
{tool.returns !== undefined && (
Returns
Declared or documented return information; not an inferred output schema.
{output(tool.returns)}
)}
{tool.codemode && (
)}
{tool.examples.length > 0 && (
Declared examples
{tool.examples.map((example) => (
{JSON.stringify(example.value, null, 2)}
))}
)}
>
)}
);
}
export function ToolInspector({ data, scope }: { data?: Capture; scope: string }) {
const tools = useMemo(() => toolDocuments(data?.value), [data?.value]);
const [query, setQuery] = useState("");
const [selected, setSelected] = useState();
const filtered = useMemo(() => {
const search = query.trim().toLocaleLowerCase();
return tools.filter((tool) =>
`${tool.name}\n${tool.description}\n${tool.codemode}`.toLocaleLowerCase().includes(search),
);
}, [tools, query]);
const tool = filtered.find((tool) => tool.id === selected) ?? filtered[0];
if (!data || !Array.isArray(data.value))
return ;
return (
Historical declared tools · preview branch · {tools.length} tools
{data.truncated && (
Captured declarations are truncated. Documentation and Raw JSON show only the available display copy.
)}
{tool &&
}
);
}