import { memo, useEffect } from 'react'; import { useUpdateNodeInternals } from '@xyflow/react'; import NodeShell from '../components/NodeShell.jsx'; import { NodeDraftInput, NodeDraftTextarea } from '../components/NodeDraftField.jsx'; import { useWorkflow } from '../context/WorkflowContext.jsx'; import { createBrowserId } from '../lib/ids.js'; import { getNodeAccent } from '../lib/nodeRegistry.js'; function SemanticBranchFlowNode({ id, data, selected, type }) { const { getNodeHandles, replaceNodeData, removeHandleConnections } = useWorkflow(); const updateNodeInternals = useUpdateNodeInternals(); const handles = getNodeHandles(type, data); const runtime = data.runtime || {}; useEffect(() => { updateNodeInternals(id); }, [id, data.choices.length, updateNodeInternals]); const addChoice = () => { replaceNodeData(id, (current) => ({ ...current, choices: [...current.choices, { id: createBrowserId('choice'), label: '' }], })); }; const updateChoice = (choiceId, label) => { replaceNodeData(id, (current) => ({ ...current, choices: current.choices.map((choice) => choice.id === choiceId && choice.label !== label ? { ...choice, label } : choice, ), })); }; const removeChoice = (choiceId) => { if (data.choices.length <= 1) { return; } removeHandleConnections(id, choiceId, 'source'); replaceNodeData(id, (current) => ({ ...current, choices: current.choices.filter((choice) => choice.id !== choiceId), })); }; const matchedChoice = data.choices.find((choice) => choice.id === runtime.matchId); return (
{data.choices.map((choice, index) => (
updateChoice(choice.id, value)} />
))}
Используйте точку с запятой для альтернатив внутри одного варианта: да; хочу еще; давай.
{data.retryOnUnclear !== false ? ( <> replaceNodeData(id, (current) => ({ ...current, retryQuestion: value, })) } /> ) : null}
{runtime.result ? `Классификация: ${runtime.result}${matchedChoice ? ` -> ${matchedChoice.label}` : ''}` : 'LLM классифицирует ответ и активирует один выход.'}
{runtime.error ?
{runtime.error}
: null}
); } export default memo(SemanticBranchFlowNode);