import type { Part, TextPart, ToolPart, Message } from "@opencode-ai/sdk" import { createMemo, For, Match, Show, Switch } from "solid-js" import { Dynamic } from "solid-js/web" import { Markdown } from "./markdown" import { Card, Checkbox, Diff, Icon } from "@opencode-ai/ui" import { Message as MessageDisplay, registerPartComponent } from "@opencode-ai/ui" import { BasicTool, GenericTool, ToolRegistry, DiffChanges } from "@opencode-ai/ui" import { getDirectory, getFilename } from "@/utils" export function Message(props: { message: Message; parts: Part[] }) { return } registerPartComponent("text", function TextPartDisplay(props) { const part = props.part as TextPart return ( ) }) registerPartComponent("reasoning", function ReasoningPartDisplay(props) { const part = props.part as any return ( ) }) registerPartComponent("tool", function ToolPartDisplay(props) { const part = props.part as ToolPart const component = createMemo(() => { const render = ToolRegistry.render(part.tool) ?? GenericTool const metadata = part.state.status === "pending" ? {} : (part.state.metadata ?? {}) const input = part.state.status === "completed" ? part.state.input : {} return ( {(error) => { const cleaned = error().replace("Error: ", "") const [title, ...rest] = cleaned.split(": ") return (
{title}
{rest.join(": ")}
{cleaned}
) }}
) }) return {component()} }) ToolRegistry.register({ name: "read", render(props) { return ( ) }, }) ToolRegistry.register({ name: "list", render(props) { return (
{props.output}
) }, }) ToolRegistry.register({ name: "glob", render(props) { return ( {props.output} ) }, }) ToolRegistry.register({ name: "grep", render(props) { const args = [] if (props.input.pattern) args.push("pattern=" + props.input.pattern) if (props.input.include) args.push("include=" + props.input.include) return (
{props.output}
) }, }) ToolRegistry.register({ name: "webfetch", render(props) { return ( ), }} >
{props.output}
) }, }) ToolRegistry.register({ name: "task", render(props) { return (
{props.output}
) }, }) ToolRegistry.register({ name: "bash", render(props) { return (
{props.output}
) }, }) ToolRegistry.register({ name: "edit", render(props) { return (
Edit
{getDirectory(props.input.filePath!)} {getFilename(props.input.filePath ?? "")}
} >
) }, }) ToolRegistry.register({ name: "write", render(props) { return (
Write
{getDirectory(props.input.filePath!)} {getFilename(props.input.filePath ?? "")}
{/* */}
} >
{props.output}
) }, }) ToolRegistry.register({ name: "todowrite", render(props) { return ( t.status === "completed").length}/${props.input.todos?.length}`, }} >
{(todo: any) => (
{todo.content}
)}
) }, })