import type { Component } from 'svelte'
import type { ToolCallResult } from '$lib/stores/chat'

export interface ToolRenderer {
  match: (tool: ToolCallResult) => boolean
  component: Component<{ tool: ToolCallResult }>
}

const registry: ToolRenderer[] = []

export function registerToolRenderer(r: ToolRenderer) {
  registry.push(r)
}

export function getToolRenderer(tool: ToolCallResult): ToolRenderer | undefined {
  return registry.find((r) => r.match(tool))
}
