/** * Web Component wrapper for AIToolRun (hand-crafted transport adapter). * Custom element: * * @generated by scripts/generate-wc-components.ts * DO NOT EDIT THE GENERATED src/wc COPY */ import React from 'react'; import { AIToolRunRuntimeBoundary } from '../components/organisms/ai/AIToolRun/AIToolRun'; import type { AIToolRunActionEvent } from '../components/organisms/ai/AIToolRun/validation'; import { BaseCompoundWC, camelToKebab, dispatchEvent, installPropAccessors, type PropDefs, registerWC, } from './_shared'; const PROP_DEFS: PropDefs = { run: 'json', headingLevel: 'number', open: 'boolean', defaultOpen: 'boolean', expandedStepIds: 'json', defaultExpandedStepIds: 'json', }; const INVALID_TRANSPORT_VALUE = Object.freeze({ invalidAIToolRunTransportValue: true, }); class AIToolRunWC extends BaseCompoundWC { get propDefs() { return PROP_DEFS; } static get observedAttributes() { return Object.keys(PROP_DEFS).map(camelToKebab); } private _hasTransportValue(name: keyof typeof PROP_DEFS): boolean { return ( Object.hasOwn(this._props, name) || this.hasAttribute(camelToKebab(name)) ); } private _readTransportValue( props: Record, name: keyof typeof PROP_DEFS, fallback?: unknown, ): unknown { if (!this._hasTransportValue(name)) return fallback; return props[name] === undefined ? INVALID_TRANSPORT_VALUE : props[name]; } protected _renderReact(): React.ReactElement { const props = this._readAllProps(); const hasOpen = this._hasTransportValue('open'); const hasExpandedStepIds = this._hasTransportValue('expandedStepIds'); return React.createElement(AIToolRunRuntimeBoundary, { run: this._readTransportValue(props, 'run'), headingLevel: this._readTransportValue(props, 'headingLevel', 2), defaultOpen: this._readTransportValue(props, 'defaultOpen', true), defaultExpandedStepIds: this._readTransportValue( props, 'defaultExpandedStepIds', [], ), ...(hasOpen ? { open: this._readTransportValue(props, 'open') } : {}), ...(hasExpandedStepIds ? { expandedStepIds: this._readTransportValue(props, 'expandedStepIds'), } : {}), onAction: (event: AIToolRunActionEvent) => dispatchEvent(this, 'action', event), onOpenChange: (open: boolean) => dispatchEvent(this, 'open-change', open), onExpandedStepIdsChange: (ids: readonly string[]) => dispatchEvent(this, 'expanded-step-ids-change', [...ids]), }); } } installPropAccessors(AIToolRunWC, PROP_DEFS); registerWC('hf-ai-tool-run', AIToolRunWC); export { AIToolRunWC }; export default AIToolRunWC;