Home / File/ llm.ts — ui Source File

llm.ts — ui Source File

Architecture documentation for llm.ts, a typescript file in the ui codebase. 7 imports, 0 dependents.

Entity Profile

Dependency Diagram

graph LR
  d4c19c52_649d_50ba_748b_40d85e37474b["llm.ts"]
  eac8f98f_e40a_7fe8_f505_372c83d20c7a["fs"]
  d4c19c52_649d_50ba_748b_40d85e37474b --> eac8f98f_e40a_7fe8_f505_372c83d20c7a
  7c0ef5ae_77fa_2db5_3105_1433ebd1e241["__index__"]
  d4c19c52_649d_50ba_748b_40d85e37474b --> 7c0ef5ae_77fa_2db5_3105_1433ebd1e241
  b5f7acc2_8550_f8f0_0425_a71c6d434acd["source"]
  d4c19c52_649d_50ba_748b_40d85e37474b --> b5f7acc2_8550_f8f0_0425_a71c6d434acd
  3760d05c_9abb_8921_1a30_9996e59e5714["__index__"]
  d4c19c52_649d_50ba_748b_40d85e37474b --> 3760d05c_9abb_8921_1a30_9996e59e5714
  b5745d66_2f51_7fb8_758d_e409c7f36c09["_legacy-styles"]
  d4c19c52_649d_50ba_748b_40d85e37474b --> b5745d66_2f51_7fb8_758d_e409c7f36c09
  c544a3e1_3972_d827_a6cc_0c6a194dbe9e["bases"]
  d4c19c52_649d_50ba_748b_40d85e37474b --> c544a3e1_3972_d827_a6cc_0c6a194dbe9e
  bfb9bc1d_9320_eaa1_c2b8_c6e4e825bbf7["__index__"]
  d4c19c52_649d_50ba_748b_40d85e37474b --> bfb9bc1d_9320_eaa1_c2b8_c6e4e825bbf7
  style d4c19c52_649d_50ba_748b_40d85e37474b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import fs from "fs"
import { ExamplesIndex } from "@/examples/__index__"

import { source } from "@/lib/source"
import { Index as StylesIndex } from "@/registry/__index__"
import { type Style } from "@/registry/_legacy-styles"
import { BASES } from "@/registry/bases"
import { Index as BasesIndex } from "@/registry/bases/__index__"

function getBaseForStyle(styleName: string) {
  for (const base of BASES) {
    if (styleName.startsWith(`${base.name}-`)) {
      return base.name
    }
  }
  return null
}

function getDemoFilePath(name: string, styleName: string) {
  const base = getBaseForStyle(styleName)
  if (!base) {
    return null
  }
  const demo = ExamplesIndex[base]?.[name]
  if (!demo) {
    return null
  }
  return demo.filePath
}

function getIndexForStyle(styleName: string) {
  const base = getBaseForStyle(styleName)
  if (base) {
    return { index: BasesIndex, key: base }
  }
  return { index: StylesIndex, key: styleName }
}

function getComponentsList() {
  const components = source.pageTree.children.find(
    (page) => page.$id === "components"
  )

  if (components?.type !== "folder") {
    return ""
  }

  const list = components.children.filter(
    (component) => component.type === "page"
  )

  return list
    .map((component) => `- [${component.name}](${component.url})`)
    .join("\n")
}

export function processMdxForLLMs(content: string, style: Style["name"]) {
  // Replace <ComponentsList /> with a markdown list of components.
  const componentsListRegex = /<ComponentsList\s*\/>/g
  content = content.replace(componentsListRegex, getComponentsList())

  const componentPreviewRegex =
    /<ComponentPreview[\s\S]*?name="([^"]+)"[\s\S]*?\/>/g

  return content.replace(componentPreviewRegex, (match, name) => {
    try {
      // Try to extract styleName from the match.
      const styleNameMatch = match.match(/styleName="([^"]+)"/)
      const effectiveStyle = styleNameMatch ? styleNameMatch[1] : style

      let src = getDemoFilePath(name, effectiveStyle)

      if (!src) {
        const { index, key } = getIndexForStyle(effectiveStyle)
        const component = index[key]?.[name]
        if (!component?.files) {
          return match
        }
        src = component.files[0]?.path
      }

      if (!src) {
        return match
      }

      let source = fs.readFileSync(src, "utf8")

      // Replace all base-specific paths.
      for (const base of BASES) {
        source = source.replaceAll(
          `@/registry/bases/${base.name}/`,
          "@/components/"
        )
        source = source.replaceAll(
          `@/examples/${base.name}/ui/`,
          "@/components/ui/"
        )
        source = source.replaceAll(`@/examples/${base.name}/lib/`, "@/lib/")
        source = source.replaceAll(`@/examples/${base.name}/hooks/`, "@/hooks/")
      }
      source = source.replaceAll(
        `@/registry/${effectiveStyle}/`,
        "@/components/"
      )
      source = source.replaceAll("export default", "export")

      return `\`\`\`tsx
${source}
\`\`\``
    } catch (error) {
      console.error(`Error processing ComponentPreview ${name}:`, error)
      return match
    }
  })
}

Subdomains

Dependencies

  • __index__
  • __index__
  • __index__
  • _legacy-styles
  • bases
  • fs
  • source

Frequently Asked Questions

What does llm.ts do?
llm.ts is a source file in the ui codebase, written in typescript. It belongs to the DocumentationAtlas domain, SearchAPI subdomain.
What functions are defined in llm.ts?
llm.ts defines 5 function(s): getBaseForStyle, getComponentsList, getDemoFilePath, getIndexForStyle, processMdxForLLMs.
What does llm.ts depend on?
llm.ts imports 7 module(s): __index__, __index__, __index__, _legacy-styles, bases, fs, source.
Where is llm.ts in the architecture?
llm.ts is located at apps/v4/lib/llm.ts (domain: DocumentationAtlas, subdomain: SearchAPI, directory: apps/v4/lib).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free