/** * Web Component wrapper for AIToolCall (hand-crafted WC adapter). * Custom element: * * Provides JSON prop parsing for `toolPart` and a null guard * so the component doesn't crash before Vue sets the prop. * * @generated by scripts/generate-wc-components.ts * DO NOT EDIT MANUALLY */ import React from 'react'; import type { ToolCallPart, ToolCallStatus } from '../components'; import { AIToolCall } from '../components'; import { BaseCompoundWC, camelToKebab, dispatchEvent, installPropAccessors, type PropDefs, registerWC, } from './_shared'; const PROP_DEFS: PropDefs = { toolPart: 'json', defaultOpen: 'boolean', open: 'boolean', }; const TOOL_CALL_STATUSES = { error: true, pending: true, running: true, success: true, } as const satisfies Record; function isRecord(value: unknown): value is Record { return typeof value === 'object' && value !== null && !Array.isArray(value); } function isToolCallStatus(value: unknown): value is ToolCallStatus { return typeof value === 'string' && value in TOOL_CALL_STATUSES; } function parseToolCallPart(value: unknown): ToolCallPart | undefined { if (!isRecord(value)) return undefined; const { args, error, result, status, toolCallId, toolName } = value; if (typeof toolCallId !== 'string' || toolCallId.length === 0) { return undefined; } if (typeof toolName !== 'string' || toolName.length === 0) { return undefined; } if (status !== undefined && !isToolCallStatus(status)) { return undefined; } if (args !== undefined && !isRecord(args)) { return undefined; } return { args, error: typeof error === 'string' ? error : undefined, result, status, toolCallId, toolName, }; } class AIToolCallWC extends BaseCompoundWC { get propDefs() { return PROP_DEFS; } static get observedAttributes() { return Object.keys(PROP_DEFS).map(camelToKebab); } protected _renderReact(): React.ReactElement { const props = this._readAllProps(); const toolPart = parseToolCallPart(props.toolPart); // Null guard: return empty fragment until toolPart is provided if (!toolPart) { return React.createElement(React.Fragment); } return React.createElement(AIToolCall, { toolPart, defaultOpen: (props.defaultOpen as boolean) ?? false, open: props.open as boolean | undefined, onOpenChange: (open: boolean) => dispatchEvent(this, 'open-change', open), }); } } installPropAccessors(AIToolCallWC, PROP_DEFS); registerWC('hf-ai-tool-call', AIToolCallWC); export { AIToolCallWC }; export default AIToolCallWC;