{"version":3,"file":"Response.mjs","names":[],"sources":["../../../../src/ai/response/Response.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\n// oxlint-disable sort-keys\nimport { Code, TextLink, Typography } from '@neo4j-ndl/react';\nimport classNames from 'classnames';\nimport { memo, useMemo, useRef } from 'react';\nimport { defaultRehypePlugins, Streamdown } from 'streamdown';\n\nimport { type CommonProps, type HtmlAttributes } from '../../_common/types';\nimport { type LanguageProp, Languages } from '../../code-block/code-languages';\nimport { CodePreview } from '../code-preview';\nimport { safeHref } from './safe-href';\n\nconst STREAMDOWN_PLACEHOLDER_PROTOCOL = 'streamdown:';\n\nconst CLOBBER_PREFIX = 'user-content-';\nconst CLOBBERABLE_PROPERTIES = [\n  'id',\n  'name',\n  'ariaDescribedBy',\n  'ariaLabelledBy',\n];\n\ntype HastNode = {\n  type: string;\n  tagName?: string;\n  properties?: Record<string, unknown>;\n  children?: HastNode[];\n};\n\nconst prefixClobberValue = (value: unknown) =>\n  typeof value === 'string' && !value.startsWith(CLOBBER_PREFIX)\n    ? `${CLOBBER_PREFIX}${value}`\n    : value;\n\nconst prefixClobberableProperties = (node: HastNode) => {\n  if (node.type === 'element' && node.properties !== undefined) {\n    for (const key of CLOBBERABLE_PROPERTIES) {\n      const value = node.properties[key];\n      if (value === undefined || value === null) {\n        continue;\n      }\n      node.properties[key] = Array.isArray(value)\n        ? value.map(prefixClobberValue)\n        : prefixClobberValue(value);\n    }\n  }\n  node.children?.forEach(prefixClobberableProperties);\n};\n\n/**\n * Streamdown 2 sanitizes with an empty `clobberPrefix`, which lets ids and\n * names from model output collide with the host document (DOM clobbering).\n * Prefixing after sanitization keeps already prefixed footnote ids intact.\n */\nconst rehypePrefixClobberableProperties = () => prefixClobberableProperties;\n\n/**\n * Strip unsafe `href`/`src` before rehype-harden. Harden 1.1.x with wildcard\n * prefixes rewrites network-path URLs (e.g. `//evil.example/path` → `/path`),\n * which would bypass `safeHref` in the React overrides.\n */\nconst stripUnsafeUrlProperty = (\n  properties: Record<string, unknown>,\n  key: 'href' | 'src',\n) => {\n  const value = properties[key];\n  if (typeof value !== 'string') {\n    return;\n  }\n  // Leave streaming placeholders for harden / the React override.\n  if (value.startsWith(STREAMDOWN_PLACEHOLDER_PROTOCOL)) {\n    return;\n  }\n  if (safeHref(value) === undefined) {\n    delete properties[key];\n  }\n};\n\n/**\n * A `srcSet` is safe only when every comma-separated URL candidate is safe.\n * Descriptors (`1x`, `2x`, `480w`, etc.) do not affect the URL check.\n */\nconst stripUnsafeSrcSet = (properties: Record<string, unknown>) => {\n  const value = properties.srcSet;\n  if (typeof value !== 'string') {\n    delete properties.srcSet;\n    return;\n  }\n\n  const candidates = value.split(',');\n  const isSafe =\n    candidates.length > 0 &&\n    candidates.every((candidate) => {\n      const [url] = candidate.trim().split(/\\s+/, 1);\n      return url !== undefined && safeHref(url) !== undefined;\n    });\n\n  if (!isSafe) {\n    delete properties.srcSet;\n  }\n};\n\nconst rejectUnsafeUrls = (node: HastNode) => {\n  if (node.type === 'element' && node.properties !== undefined) {\n    if (node.tagName === 'a') {\n      stripUnsafeUrlProperty(node.properties, 'href');\n    } else if (node.tagName === 'img') {\n      stripUnsafeUrlProperty(node.properties, 'src');\n    } else if (node.tagName === 'source') {\n      stripUnsafeSrcSet(node.properties);\n    }\n  }\n  node.children?.forEach(rejectUnsafeUrls);\n};\n\nconst rehypeRejectUnsafeUrls = () => rejectUnsafeUrls;\n\nconst withPluginOptions = (\n  plugin: (typeof defaultRehypePlugins)[string],\n  options: Record<string, unknown>,\n): NonNullable<\n  React.ComponentProps<typeof Streamdown>['rehypePlugins']\n>[number] => {\n  if (Array.isArray(plugin)) {\n    const existingOptions =\n      typeof plugin[1] === 'object' &&\n      plugin[1] !== null &&\n      !Array.isArray(plugin[1])\n        ? plugin[1]\n        : {};\n    return [plugin[0], { ...existingOptions, ...options }] as NonNullable<\n      React.ComponentProps<typeof Streamdown>['rehypePlugins']\n    >[number];\n  }\n  return [plugin, options] as NonNullable<\n    React.ComponentProps<typeof Streamdown>['rehypePlugins']\n  >[number];\n};\n\n// Streamdown 2.7 defaults: raw, sanitize, harden (katex is no longer included).\nconst rehypePlugins: NonNullable<\n  React.ComponentProps<typeof Streamdown>['rehypePlugins']\n> = [\n  defaultRehypePlugins.raw,\n  defaultRehypePlugins.sanitize,\n  // Must run before harden so network-path URLs are not rewritten to paths.\n  rehypeRejectUnsafeUrls,\n  // text-only: incomplete streamdown: URLs that harden rejects must not surface\n  // as visible \" [blocked]\" markers from the default indicator policy.\n  withPluginOptions(defaultRehypePlugins.harden, {\n    linkBlockPolicy: 'text-only',\n    imageBlockPolicy: 'text-only',\n  }),\n  rehypePrefixClobberableProperties,\n];\n\ntype ResponseProps = {\n  /** Markdown content from the AI. URLs and attributes are sanitized before render. */\n  children: string;\n  /** Whether the response is animating */\n  isAnimating?: React.ComponentProps<typeof Streamdown>['isAnimating'];\n};\n\nconst ALLOWED_PROP = /^(className|id|name|title|aria-|data-|role)/;\n\nconst pickSafeProps = <T extends React.ElementType>(\n  props: Record<string, unknown>,\n): HtmlAttributes<T> =>\n  Object.fromEntries(\n    Object.entries(props).filter(([key]) => ALLOWED_PROP.test(key)),\n  ) as HtmlAttributes<T>;\n\n/**\n * Absolute `http:` and `https:` URLs are external when their origin differs\n * from the page. Same-origin absolute URLs, relative paths, fragments, and\n * `mailto:` stay internal. Visual only — both still open in a new tab.\n */\nconst isExternalHref = (href: string): boolean => {\n  if (!/^https?:/i.test(href)) {\n    return false;\n  }\n  if (typeof window === 'undefined') {\n    return true;\n  }\n  try {\n    return new URL(href).origin !== window.location.origin;\n  } catch {\n    return true;\n  }\n};\n\n/**\n * The component is used to display the response from an LLM.\n * It handles markdown rendering and streaming.\n *\n * @remarks\n * Treat `children` as untrusted. Link and image URLs are limited to `http:`,\n * `https:`, `mailto:`, and same-origin relative or fragment paths. Unsafe\n * schemes (for example `javascript:`) and network-path URLs (for example\n * `//evil.example`) render as plain text for links and are omitted for images.\n * Markdown attributes are allow-listed so event handlers cannot reach the DOM.\n * Allowed links open in a new tab with a fixed `rel=\"noopener noreferrer\"`\n * (`target` and `rel` from markdown are ignored). Absolute `http:` and\n * `https:` links use `TextLink` `type=\"external\"` when their origin differs\n * from the page, and `type=\"internal\"` when it matches. Relative, fragment,\n * and `mailto:` links use `type=\"internal\"`.\n * Ids and related attributes from model output are prefixed with\n * `user-content-` to avoid colliding with the host document.\n *\n * @alpha - Changes to this component may be breaking.\n */\nconst Response = memo(\n  ({\n    className,\n    children,\n    isAnimating = false,\n    ref,\n    style,\n    htmlAttributes,\n    ...restProps\n  }: CommonProps<'div', ResponseProps>) => {\n    // Use a ref to store the current markdown content so we can check for unclosed fences\n    // without recreating the components object on every render\n    const childrenRef = useRef(children);\n    childrenRef.current = children;\n\n    const components: React.ComponentProps<typeof Streamdown>['components'] =\n      useMemo(\n        () => ({\n          // oxlint-disable-next-line no-unused-vars\n          ol: ({ node, children, className, ref: _ref, ...props }) => (\n            <ol className={className} {...props}>\n              {children}\n            </ol>\n          ),\n          // oxlint-disable-next-line no-unused-vars\n          ul: ({ node, children, className, ref: _ref, ...props }) => (\n            <ul className={classNames(className)} {...props}>\n              {children}\n            </ul>\n          ),\n          // oxlint-disable-next-line no-unused-vars\n          li: ({ node, children, className, ref: _ref, ...props }) => (\n            <li className={className} {...props}>\n              {children}\n            </li>\n          ),\n          // oxlint-disable-next-line no-unused-vars\n          hr: ({ node, className, ref: _ref, ...props }) => (\n            <hr className={classNames(className)} {...props} />\n          ),\n          // oxlint-disable-next-line no-unused-vars\n          strong: ({\n            node: _node,\n            children,\n            className,\n            style,\n            ref: _ref,\n            ...props\n          }) => (\n            <Typography\n              as=\"strong\"\n              variant=\"body-medium\"\n              className={className}\n              style={{ ...style, fontWeight: 'bold' }}\n              {...props}\n            >\n              {children}\n            </Typography>\n          ),\n          // oxlint-disable-next-line no-unused-vars\n          em: ({ node, children, className, style, ref: _ref, ...props }) => (\n            <Typography\n              as=\"em\"\n              variant=\"body-medium\"\n              className={className}\n              style={{ ...style, fontStyle: 'italic' }}\n              {...props}\n            >\n              {children}\n            </Typography>\n          ),\n          // oxlint-disable-next-line no-unused-vars, id-length\n          a: ({ node: _node, children, className, href, ...props }) => {\n            // Streamdown marks links whose URL is still streaming with a placeholder href\n            if (href?.startsWith(STREAMDOWN_PLACEHOLDER_PROTOCOL) === true) {\n              return <span className={className}>{children}</span>;\n            }\n            const cleanHref = safeHref(href);\n            if (cleanHref === undefined) {\n              // Unsafe or unknown scheme: render text, not a clickable link.\n              return <span className={className}>{children}</span>;\n            }\n            return (\n              <TextLink\n                type={isExternalHref(cleanHref) ? 'external' : 'internal'}\n                className={className}\n                href={cleanHref}\n                // Harden sets target=\"_blank\" on every allowed link. Re-apply\n                // it here: TextLink's internal type defaults to the same tab,\n                // and the allow-list drops `target` and `rel` from markdown.\n                target=\"_blank\"\n                htmlAttributes={{\n                  ...pickSafeProps<'a'>(props),\n                  rel: 'noopener noreferrer',\n                }}\n              >\n                {children}\n              </TextLink>\n            );\n          },\n          // oxlint-disable-next-line no-unused-vars\n          h1: ({ node, children, className, ...props }) => (\n            <h1 className={className} {...props}>\n              {children}\n            </h1>\n          ),\n          // oxlint-disable-next-line no-unused-vars\n          h2: ({ node, children, className, ...props }) => (\n            <h2 className={className} {...props}>\n              {children}\n            </h2>\n          ),\n          // oxlint-disable-next-line no-unused-vars\n          h3: ({ node, children, className, ...props }) => (\n            <h3 className={className} {...props}>\n              {children}\n            </h3>\n          ),\n          // oxlint-disable-next-line no-unused-vars\n          h4: ({ node, children, className, ...props }) => (\n            <h4 className={className} {...props}>\n              {children}\n            </h4>\n          ),\n          // oxlint-disable-next-line no-unused-vars\n          h5: ({ node, children, className, ...props }) => (\n            <h5 className={className} {...props}>\n              {children}\n            </h5>\n          ),\n          // oxlint-disable-next-line no-unused-vars\n          h6: ({ node, children, className, ...props }) => (\n            <h6 className={className} {...props}>\n              {children}\n            </h6>\n          ),\n          // oxlint-disable-next-line no-unused-vars\n          table: ({ node, children, className, ref: _ref, ...props }) => (\n            <div className=\"ndl-ai-response-table-wrapper\">\n              <table className={className} {...props}>\n                {children}\n              </table>\n            </div>\n          ),\n          // oxlint-disable-next-line no-unused-vars\n          thead: ({ node, children, className, ref: _ref, ...props }) => (\n            <thead className={className} {...props}>\n              {children}\n            </thead>\n          ),\n          // oxlint-disable-next-line no-unused-vars\n          tbody: ({ node, children, className, ref: _ref, ...props }) => (\n            <tbody className={className} {...props}>\n              {children}\n            </tbody>\n          ),\n          // oxlint-disable-next-line no-unused-vars\n          tr: ({ node, children, className, ref: _ref, ...props }) => (\n            <tr className={className} {...props}>\n              {children}\n            </tr>\n          ),\n          // oxlint-disable-next-line no-unused-vars\n          th: ({ node, children, className, ref: _ref, ...props }) => (\n            <th className={className} {...props}>\n              {children}\n            </th>\n          ),\n          // oxlint-disable-next-line no-unused-vars\n          td: ({ node, children, className, ref: _ref, ...props }) => (\n            <td className={className} {...props}>\n              {children}\n            </td>\n          ),\n          // oxlint-disable-next-line no-unused-vars\n          sup: ({ node, children, className, ref: _ref, ...props }) => (\n            <sup className={className} {...props}>\n              {children}\n            </sup>\n          ),\n          // oxlint-disable-next-line no-unused-vars\n          sub: ({ node, children, className, ref: _ref, ...props }) => (\n            <sub className={className} {...props}>\n              {children}\n            </sub>\n          ),\n          // oxlint-disable-next-line no-unused-vars\n          blockquote: ({ node, children, className, ref: _ref, ...props }) => (\n            <blockquote className={classNames(className)} {...props}>\n              {children}\n            </blockquote>\n          ),\n          code: ({ node, className, children: codeChildren, ...props }) => {\n            const isInline =\n              node?.position?.start.line === node?.position?.end.line;\n\n            const nodeClassNamesRaw = node?.properties?.className;\n            const nodeClassNamesArray: string[] = [];\n\n            if (typeof nodeClassNamesRaw === 'string') {\n              nodeClassNamesArray.push.apply(\n                nodeClassNamesArray,\n                nodeClassNamesRaw.split(' '),\n              );\n            } else if (Array.isArray(nodeClassNamesRaw)) {\n              nodeClassNamesArray.push.apply(\n                nodeClassNamesArray,\n                nodeClassNamesRaw as string[],\n              );\n            }\n\n            let language: LanguageProp | 'text' = 'text';\n            const rawLanguage = nodeClassNamesArray.find((string: string) =>\n              string.startsWith('language-'),\n            );\n            if (rawLanguage !== undefined) {\n              language =\n                (rawLanguage.replace('language-', '') as LanguageProp) ??\n                'text';\n            }\n            language = (Languages as readonly string[]).includes(language)\n              ? (language as LanguageProp)\n              : 'text';\n            if (isInline) {\n              return (\n                <Code\n                  isRunnable={false}\n                  className={className}\n                  htmlAttributes={props}\n                >\n                  {codeChildren}\n                </Code>\n              );\n            }\n            if (typeof codeChildren === 'string') {\n              // Check if code fences are balanced in the markdown\n              // If there are an odd number of fences, it means there's an unclosed code block\n              const fenceMatches = childrenRef.current.match(/```/g);\n              const fenceCount = fenceMatches ? fenceMatches.length : 0;\n              const hasUnclosedFence = fenceCount % 2 !== 0;\n\n              // Show loading state when there's an unclosed fence (code block is streaming)\n              const isCodeBlockLoading = hasUnclosedFence;\n              return (\n                <CodePreview\n                  key={props.key}\n                  code={codeChildren}\n                  isLoading={isCodeBlockLoading}\n                  language={language}\n                  className={className}\n                  htmlAttributes={{\n                    ...props,\n                  }}\n                />\n              );\n            } else {\n              return <code className={className}>{codeChildren}</code>;\n            }\n          },\n          // oxlint-disable-next-line no-unused-vars\n          pre: ({ node, className, children, ref: _ref, ...props }) => {\n            return (\n              <pre className={className} {...props}>\n                {children}\n              </pre>\n            );\n          },\n          // oxlint-disable-next-line no-unused-vars, id-length\n          p: ({ node: _node, children, className, ref: _ref, ...props }) => (\n            <Typography\n              as=\"p\"\n              variant=\"body-medium\"\n              className={classNames(className)}\n              {...props}\n            >\n              {children}\n            </Typography>\n          ),\n          // oxlint-disable-next-line no-unused-vars\n          img: ({ node, className, src, alt, ref: _ref, ...props }) => {\n            if (\n              typeof src === 'string' &&\n              src.startsWith(STREAMDOWN_PLACEHOLDER_PROTOCOL)\n            ) {\n              return null;\n            }\n            const cleanSrc = safeHref(src);\n            if (cleanSrc === undefined) {\n              return null;\n            }\n            return (\n              <img\n                className={classNames(className)}\n                src={cleanSrc}\n                alt={alt}\n                {...pickSafeProps<'img'>(props)}\n              />\n            );\n          },\n        }),\n        [],\n      );\n\n    return (\n      <div\n        ref={ref}\n        style={style}\n        className={classNames('ndl-ai-response', className)}\n        {...restProps}\n        {...htmlAttributes}\n      >\n        <Streamdown\n          isAnimating={isAnimating}\n          parseIncompleteMarkdown={isAnimating}\n          components={components}\n          rehypePlugins={rehypePlugins}\n        >\n          {children}\n        </Streamdown>\n      </div>\n    );\n  },\n  (prevProps, nextProps) => prevProps.children === nextProps.children,\n);\n\nResponse.displayName = 'Response';\n\nexport { Response };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyOI;CACA;CACA;CACA;CACA;CACA;;;CAYa;CAAM;CAAU;CAAW;;;CAM3B;CAAM;CAAU;CAAW;;;CAM3B;CAAM;CAAU;CAAW;;;CAM3B;CAAM;CAAW;;;CAKtB;CACA;CACA;CACA;CACA;;;CAcK;CAAM;CAAU;CAAW;CAAO;;;CAYnC;CAAa;CAAU;CAAW;;;CA6BjC;CAAM;CAAU;;;CAMhB;CAAM;CAAU;;;CAMhB;CAAM;CAAU;;;CAMhB;CAAM;CAAU;;;CAMhB;CAAM;CAAU;;;CAMhB;CAAM;CAAU;;;CAMb;CAAM;CAAU;CAAW;;;CAQ3B;CAAM;CAAU;CAAW;;;CAM3B;CAAM;CAAU;CAAW;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