{"version":3,"file":"Reasoning.mjs","names":[],"sources":["../../../../src/ai/reasoning/Reasoning.tsx"],"sourcesContent":["/*!\n *\n *  Copyright (c) \"Neo4j\"\n *  Neo4j Sweden AB [http://neo4j.com]\n *\n *  This file is part of Neo4j.\n *\n *  Neo4j is free software: you can redistribute it and/or modify\n *  it under the terms of the GNU General Public License as published by\n *  the Free Software Foundation, either version 3 of the License, or\n *  (at your option) any later version.\n *\n *  This program is distributed in the hope that it will be useful,\n *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n *  GNU General Public License for more details.\n *\n *  You should have received a copy of the GNU General Public License\n *  along with this program.  If not, see <http://www.gnu.org/licenses/>.\n */\n\nimport { Typography } from '@neo4j-ndl/react';\nimport classNames from 'classnames';\nimport { useId, useState } from 'react';\n\nimport { type CommonProps } from '../../_common/types';\nimport { ChevronDownIconOutline } from '../../icons/generated/heroIcons/ChevronDownIconOutline';\nimport { Presence } from '../presence';\nimport { formatThinkingDuration } from '../thinking/thinking-duration-formatter';\n\ntype ReasoningProps = {\n  /** What should be displayed inside the reasoning component. */\n  children?: React.ReactNode;\n  /** Whether the AI is thinking */\n  isThinking?: boolean;\n  /** The duration of the thinking in milliseconds */\n  thinkingMs?: number;\n  /** The current action the AI is performing */\n  currentAction?: string;\n};\n\n/**\n * The component is used to display the reasoning state of an LLM.\n * It has an accordion like behavior to show the reasoning steps.\n *\n * @alpha - Changes to this component may be breaking.\n */\nconst ReasoningComponent = ({\n  isThinking = true,\n  thinkingMs = 1000,\n  currentAction = 'Thinking',\n  children,\n  className,\n  style,\n  htmlAttributes,\n  ref,\n  ...restProps\n}: CommonProps<'div', ReasoningProps>) => {\n  const classes = classNames('ndl-ai-reasoning', className);\n  const [isExpanded, setIsExpanded] = useState(false);\n  const shouldShowChildren = isExpanded && isThinking === false;\n  const buttonId = useId();\n  const panelId = useId();\n\n  const { value: thinkingDuration, unit } = formatThinkingDuration(thinkingMs);\n\n  return (\n    <div\n      ref={ref}\n      className={classes}\n      style={style}\n      {...restProps}\n      {...htmlAttributes}\n    >\n      <Typography\n        variant=\"label\"\n        className={classNames('ndl-ai-reasoning-header', {\n          'ndl-expanded': isExpanded,\n        })}\n        {...(!isThinking\n          ? {\n              as: 'button',\n              htmlAttributes: {\n                'aria-controls': panelId,\n                'aria-expanded': isExpanded,\n                id: buttonId,\n                onClick: () => setIsExpanded(!isExpanded),\n                type: 'button',\n              },\n            }\n          : { as: 'div', htmlAttributes: { id: buttonId } })}\n      >\n        {isThinking === true ? (\n          <>\n            <Presence\n              isThinking={isThinking}\n              className=\"ndl-ai-reasoning-presence\"\n            />\n            <span className=\"ndl-ai-reasoning-header-text\">\n              {currentAction}...\n            </span>\n          </>\n        ) : (\n          <>\n            <span>\n              Thought for {thinkingDuration} {unit}\n            </span>\n            <ChevronDownIconOutline\n              className={classNames('ndl-ai-reasoning-chevron', {\n                'ndl-expanded': isExpanded,\n              })}\n            />\n          </>\n        )}\n      </Typography>\n      <div\n        className={classNames('ndl-ai-reasoning-content', {\n          'ndl-expanded': shouldShowChildren,\n        })}\n        inert={!shouldShowChildren}\n        aria-hidden={!shouldShowChildren}\n        aria-labelledby={buttonId}\n        role=\"region\"\n        id={panelId}\n      >\n        <div className=\"ndl-ai-reasoning-content-inner\">\n          <div className=\"ndl-ai-reasoning-content-inner-2\">{children}</div>\n        </div>\n      </div>\n    </div>\n  );\n};\n\ntype SectionProps = {\n  /** The heading of the section */\n  heading?: React.ReactNode;\n  /** The children of the section */\n  children?: React.ReactNode;\n  /** The visual leading the section */\n  leadingVisual?: React.ReactNode;\n};\n\nconst Section = ({\n  heading,\n  leadingVisual,\n  children,\n  className,\n  style,\n  htmlAttributes,\n  ref,\n  ...restProps\n}: CommonProps<'div', SectionProps>) => {\n  const classes = classNames('ndl-ai-reasoning-section', className);\n\n  return (\n    <div\n      ref={ref}\n      className={classes}\n      style={style}\n      {...restProps}\n      {...htmlAttributes}\n    >\n      <div className=\"ndl-ai-reasoning-section-header\">\n        <div className=\"ndl-ai-reasoning-section-leading\">{leadingVisual}</div>\n        <Typography variant=\"subheading-small\">{heading}</Typography>\n      </div>\n      <div className=\"ndl-ai-reasoning-section-content\">\n        <div className=\"ndl-ai-reasoning-section-content-line-container\">\n          <div className=\"ndl-ai-reasoning-section-content-line\" />\n        </div>\n        <div className=\"ndl-ai-reasoning-section-content-children\">\n          {children}\n        </div>\n      </div>\n    </div>\n  );\n};\n\nconst Footer = ({\n  children,\n  className,\n  style,\n  htmlAttributes,\n  ref,\n  ...restProps\n}: CommonProps<'div', { children: React.ReactNode }>) => {\n  const classes = classNames('ndl-ai-reasoning-footer', className);\n  return (\n    <Typography\n      as=\"div\"\n      variant=\"body-small\"\n      className={classes}\n      style={style}\n      ref={ref}\n      {...restProps}\n      {...htmlAttributes}\n    >\n      {children}\n    </Typography>\n  );\n};\n\nconst Reasoning = Object.assign(ReasoningComponent, {\n  Footer,\n  Section,\n});\n\nexport { Reasoning };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgDE;CACA;CACA;CACA;CACA;CACA;CACA;CACA;;;CAwFA;CACA;CACA;CACA;CACA;CACA;CACA;;;CA8BA;CACA;CACA;CACA;CACA;;;;;;;;AAxIF,MAAM,sBAAsB,SAUc;CAVd,IAAA,EAC1B,aAAa,MACb,aAAa,KACb,gBAAgB,YAChB,UACA,WACA,OACA,gBACA,QAAA,MACG,YAAA,yBAAA,MAAA,SAAA;CAEH,MAAM,UAAU,WAAW,oBAAoB,SAAS;CACxD,MAAM,CAAC,YAAY,iBAAiB,SAAS,KAAK;CAClD,MAAM,qBAAqB,cAAc,eAAe;CACxD,MAAM,WAAW,MAAM;CACvB,MAAM,UAAU,MAAM;CAEtB,MAAM,EAAE,OAAO,kBAAkB,SAAS,uBAAuB,UAAU;CAE3E,OACE,qBAAC,OAAA,eAAA,eAAA,eAAA;EACM;EACL,WAAW;EACJ;CACH,GAAA,SAAA,GACA,cA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