import { useCallback, useMemo } from 'react';
import { applyToolResult, createToolsetRenderer, } from "../utils/toolset/index.js";
/**
 * Wire a toolset into the chat: returns a `MessageRendererRegistry` that
 * renders tool parts via the toolset and a `handleToolResult` callback
 * that merges results into history. To react to tool completion (e.g.
 * forward to the model), pair with `useToolResultContinuation`.
 *
 * Pass the same `toolset` reference across renders (e.g. via `useMemo` or
 * `createToolset`) so the registry stays stable.
 */
export function useToolset(options) {
    const { toolset, setMessages, registry } = options;
    const handleToolResult = useCallback((event) => {
        setMessages((prev) => applyToolResult(prev, event));
    }, [setMessages]);
    const messageRendererRegistry = useMemo(() => createToolsetRenderer(toolset, {
        onToolResult: handleToolResult,
        registry,
    }), [toolset, handleToolResult, registry]);
    return { messageRendererRegistry, handleToolResult };
}
//# sourceMappingURL=useToolset.js.map
