@cdxgen/cdxgen 0.0.1 → 13.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +921 -87
- package/bin/audit.js +239 -0
- package/bin/cdxgen.js +2324 -0
- package/bin/convert.js +213 -0
- package/bin/evinse.js +353 -0
- package/bin/hbom.js +495 -0
- package/bin/repl.js +2224 -0
- package/bin/sign.js +195 -0
- package/bin/tracebom.js +295 -0
- package/bin/validate.js +268 -0
- package/bin/verify.js +189 -0
- package/data/README.md +307 -0
- package/data/bom-1.4.schema.json +1605 -0
- package/data/bom-1.5.schema.json +3660 -0
- package/data/bom-1.6.schema.json +5511 -0
- package/data/bom-1.7.schema.json +6700 -0
- package/data/cbomosdb-queries.json +68 -0
- package/data/component-tags.json +339 -0
- package/data/container-knowledge-index.json +125 -0
- package/data/cosdb-queries.json +17 -0
- package/data/crypto-oid.json +1998 -0
- package/data/cryptography-defs.json +3793 -0
- package/data/cryptography-defs.schema.json +576 -0
- package/data/cyclonedx-2.0-bundled.schema.json +7182 -0
- package/data/frameworks-list.json +219 -0
- package/data/glibc-stdlib.json +117 -0
- package/data/gtfobins-index.json +6296 -0
- package/data/helpers/init.gradle +71 -0
- package/data/jsf-0.82.schema.json +211 -0
- package/data/known-licenses.json +82 -0
- package/data/lic-mapping.json +338 -0
- package/data/license-aliases.json +6624 -0
- package/data/license-db.json +39059 -0
- package/data/license-deprecations.json +302 -0
- package/data/lolbas-index.json +150 -0
- package/data/predictive-audit-allowlist.json +11 -0
- package/data/pypi-pkg-aliases.json +1199 -0
- package/data/python-stdlib.json +308 -0
- package/data/queries-darwin.json +193 -0
- package/data/queries-win.json +257 -0
- package/data/queries.json +268 -0
- package/data/ruby-known-modules.json +281 -0
- package/data/rules/ai-agent-governance.yaml +323 -0
- package/data/rules/ai-bom.yaml +268 -0
- package/data/rules/ai-oversight.yaml +186 -0
- package/data/rules/ai-provenance.yaml +92 -0
- package/data/rules/asar-archives.yaml +150 -0
- package/data/rules/cbom-security.yaml +165 -0
- package/data/rules/chrome-extensions.yaml +248 -0
- package/data/rules/ci-permissions.yaml +802 -0
- package/data/rules/container-risk.yaml +353 -0
- package/data/rules/dependency-sources.yaml +236 -0
- package/data/rules/golem-go.yaml +229 -0
- package/data/rules/hbom-compliance.yaml +325 -0
- package/data/rules/hbom-performance.yaml +307 -0
- package/data/rules/hbom-security.yaml +248 -0
- package/data/rules/host-topology.yaml +165 -0
- package/data/rules/mcp-servers.yaml +388 -0
- package/data/rules/obom-runtime.yaml +1776 -0
- package/data/rules/package-integrity.yaml +364 -0
- package/data/rules/rootfs-hardening.yaml +179 -0
- package/data/rules/vscode-extensions.yaml +237 -0
- package/data/spdx-export.schema.json +6794 -0
- package/data/spdx-license-list.json +7449 -0
- package/data/spdx-licenses.json +759 -0
- package/data/spdx.schema.json +819 -0
- package/data/templates/README.md +3 -0
- package/data/templates/asvs-4.0.3.cdx.json +2943 -0
- package/data/templates/asvs-5.0.cdx.json +3046 -0
- package/data/templates/bsimm-v13.cdx.json +1008 -0
- package/data/templates/masvs-2.0.0.cdx.json +225 -0
- package/data/templates/nist-ssdf-1.1.cdx.json +828 -0
- package/data/templates/pcissc-secure-slc-1.1.cdx.json +1027 -0
- package/data/templates/scvs-1.0.0.cdx.json +813 -0
- package/data/templates/ssaf-DRAFT-2023-11.cdx.json +127 -0
- package/data/vendor-alias.json +41967 -0
- package/data/wrapdb-releases.json +4227 -0
- package/index.cjs +15 -0
- package/lib/audit/index.js +2800 -0
- package/lib/audit/progress.js +114 -0
- package/lib/audit/reporters.js +937 -0
- package/lib/audit/scoring.js +560 -0
- package/lib/audit/targets.js +798 -0
- package/lib/cli/bomAssembly.js +1833 -0
- package/lib/cli/cliOptions.js +513 -0
- package/lib/cli/index.js +2759 -0
- package/lib/cli/jsBom.js +2087 -0
- package/lib/cli/jvmBom.js +1858 -0
- package/lib/cli/managedBom.js +2083 -0
- package/lib/cli/nativeBom.js +2125 -0
- package/lib/core/activity.js +1087 -0
- package/lib/core/env.js +719 -0
- package/lib/core/fs.js +1058 -0
- package/lib/core/httpClient.js +730 -0
- package/lib/core/logger.js +142 -0
- package/lib/core/parallel.js +323 -0
- package/lib/core/paths.js +70 -0
- package/lib/core/projectConfig.js +122 -0
- package/lib/core/propertySanitizer.js +174 -0
- package/lib/core/spdx.js +5 -0
- package/lib/core/state.js +59 -0
- package/lib/core/text.js +207 -0
- package/lib/core/ui.js +876 -0
- package/lib/core/urls.js +84 -0
- package/lib/ecosystems/asarutils.js +1636 -0
- package/lib/ecosystems/bunutils.js +402 -0
- package/lib/ecosystems/caxa.js +77 -0
- package/lib/ecosystems/chromextutils.js +1174 -0
- package/lib/ecosystems/cmakeResolver.js +587 -0
- package/lib/ecosystems/cppEvidence.js +305 -0
- package/lib/ecosystems/denoutils.js +1094 -0
- package/lib/ecosystems/dotnetutils.js +132 -0
- package/lib/ecosystems/ecosystems.js +2772 -0
- package/lib/ecosystems/golem.js +1807 -0
- package/lib/ecosystems/gradleutils.js +1048 -0
- package/lib/ecosystems/jsEvidence.js +317 -0
- package/lib/ecosystems/npmutils.js +586 -0
- package/lib/ecosystems/parsers-bazel.js +875 -0
- package/lib/ecosystems/parsers-dotnet.js +1430 -0
- package/lib/ecosystems/parsers-gleam.js +302 -0
- package/lib/ecosystems/parsers-go.js +818 -0
- package/lib/ecosystems/parsers-js.js +4222 -0
- package/lib/ecosystems/parsers-jvm.js +948 -0
- package/lib/ecosystems/parsers-misc.js +3191 -0
- package/lib/ecosystems/parsers-python.js +2070 -0
- package/lib/ecosystems/parsers-rust.js +1294 -0
- package/lib/ecosystems/parsers-zig.js +861 -0
- package/lib/ecosystems/pep770.js +341 -0
- package/lib/ecosystems/pylockutils.js +427 -0
- package/lib/ecosystems/pythonutils.js +1281 -0
- package/lib/ecosystems/registryProvenance.js +1003 -0
- package/lib/ecosystems/remote/huggingface.js +1343 -0
- package/lib/ecosystems/rubyutils.js +1629 -0
- package/lib/ecosystems/rusi.js +820 -0
- package/lib/ecosystems/sbtutils.js +972 -0
- package/lib/ecosystems/tea.js +607 -0
- package/lib/ecosystems/utils.js +575 -0
- package/lib/ecosystems/zigResolver.js +410 -0
- package/lib/evinser/db.js +145 -0
- package/lib/evinser/evinser.js +2362 -0
- package/lib/evinser/scalasem.js +65 -0
- package/lib/evinser/swiftsem.js +767 -0
- package/lib/helpers/annotationFormatter.js +84 -0
- package/lib/helpers/bomSigner.js +312 -0
- package/lib/helpers/exportUtils.js +160 -0
- package/lib/helpers/remote/dependency-track.js +117 -0
- package/lib/helpers/versutils.js +202 -0
- package/lib/helpers/vsixutils.js +1069 -0
- package/lib/inventory/agentFormulationParser.js +322 -0
- package/lib/inventory/aiCollector.js +2140 -0
- package/lib/inventory/aiInventory.js +414 -0
- package/lib/inventory/aiModelVariants.js +121 -0
- package/lib/inventory/aiOversightCollector.js +661 -0
- package/lib/inventory/aiProvenanceCollector.js +822 -0
- package/lib/inventory/analyzer.js +6089 -0
- package/lib/inventory/analyzerScope.js +807 -0
- package/lib/inventory/astWorker.js +20 -0
- package/lib/inventory/atomUtils.js +1092 -0
- package/lib/inventory/auditCategories.js +192 -0
- package/lib/inventory/bomUtils.js +369 -0
- package/lib/inventory/cacheCommands.js +182 -0
- package/lib/inventory/cacheDir.js +104 -0
- package/lib/inventory/cbomutils.js +590 -0
- package/lib/inventory/cdxrs.js +434 -0
- package/lib/inventory/ciParsers/azurePipelines.js +295 -0
- package/lib/inventory/ciParsers/circleCi.js +286 -0
- package/lib/inventory/ciParsers/common.js +24 -0
- package/lib/inventory/ciParsers/githubActions.js +2434 -0
- package/lib/inventory/ciParsers/gitlabCi.js +213 -0
- package/lib/inventory/ciParsers/jenkins.js +180 -0
- package/lib/inventory/citations.js +234 -0
- package/lib/inventory/communityAiConfigParser.js +756 -0
- package/lib/inventory/containerRisk.js +204 -0
- package/lib/inventory/cryptoAlgorithmFamily.js +258 -0
- package/lib/inventory/deps.js +807 -0
- package/lib/inventory/depsUtils.js +588 -0
- package/lib/inventory/display.js +2128 -0
- package/lib/inventory/dosai.js +601 -0
- package/lib/inventory/dosaiParsers.js +154 -0
- package/lib/inventory/dynamic.js +145 -0
- package/lib/inventory/envcontext.js +1789 -0
- package/lib/inventory/evidenceUtils.js +774 -0
- package/lib/inventory/fetchBatch.js +779 -0
- package/lib/inventory/fetchRate.js +255 -0
- package/lib/inventory/forgeEnricher.js +300 -0
- package/lib/inventory/formulationParsers.js +422 -0
- package/lib/inventory/gtfobins.js +339 -0
- package/lib/inventory/hbom.js +719 -0
- package/lib/inventory/hbomAnalysis.js +310 -0
- package/lib/inventory/hbomLoader.js +35 -0
- package/lib/inventory/hostTopology.js +835 -0
- package/lib/inventory/inventoryStats.js +100 -0
- package/lib/inventory/jsonLike.js +121 -0
- package/lib/inventory/licenseEnhancer.js +918 -0
- package/lib/inventory/lolbas.js +285 -0
- package/lib/inventory/mcp.js +253 -0
- package/lib/inventory/mcpConfigParser.js +683 -0
- package/lib/inventory/mcpDiscovery.js +112 -0
- package/lib/inventory/mcpPinning.js +209 -0
- package/lib/inventory/osPackageResolver.js +493 -0
- package/lib/inventory/osinfo.js +277 -0
- package/lib/inventory/osqueryTransform.js +274 -0
- package/lib/inventory/plugins.js +466 -0
- package/lib/inventory/protobom.js +231 -0
- package/lib/inventory/protobomLoader.js +43 -0
- package/lib/inventory/provenanceUtils.js +224 -0
- package/lib/inventory/purl.js +749 -0
- package/lib/inventory/rustFormulationParser.js +339 -0
- package/lib/inventory/sbomDocument.js +340 -0
- package/lib/inventory/source.js +1488 -0
- package/lib/inventory/spdx.js +361 -0
- package/lib/inventory/spdxExpression.js +512 -0
- package/lib/inventory/spdxUtils.js +107 -0
- package/lib/inventory/table.js +263 -0
- package/lib/inventory/traceRunner.js +439 -0
- package/lib/inventory/unicodeScan.js +147 -0
- package/lib/managers/binary.js +3307 -0
- package/lib/managers/containerutils.js +125 -0
- package/lib/managers/docker.js +2145 -0
- package/lib/managers/dockerConnection.js +162 -0
- package/lib/managers/oci.js +704 -0
- package/lib/managers/piptree.js +267 -0
- package/lib/parsers/cmakeCache.js +199 -0
- package/lib/parsers/gguf.js +492 -0
- package/lib/parsers/gitAiNotes.js +233 -0
- package/lib/parsers/gitmodules.js +239 -0
- package/lib/parsers/htmlExtract.js +610 -0
- package/lib/parsers/huggingfaceManifest.js +551 -0
- package/lib/parsers/huggingfaceUtils.js +506 -0
- package/lib/parsers/iri.js +618 -0
- package/lib/parsers/npmrc.js +99 -0
- package/lib/parsers/ollama.js +101 -0
- package/lib/parsers/xml.js +841 -0
- package/lib/server/openapi.yaml +433 -0
- package/lib/server/server.js +616 -0
- package/lib/stages/postgen/annotator.js +977 -0
- package/lib/stages/postgen/auditBom.js +468 -0
- package/lib/stages/postgen/postgen.js +1239 -0
- package/lib/stages/postgen/ruleEngine.js +731 -0
- package/lib/stages/postgen/sortBom.js +195 -0
- package/lib/stages/postgen/spdxConverter.js +796 -0
- package/lib/stages/postgen/specVersionCompat.js +703 -0
- package/lib/stages/pregen/envAudit.js +388 -0
- package/lib/stages/pregen/pregen.js +637 -0
- package/lib/third-party/README.md +9 -0
- package/lib/third-party/arborist/CHANGELOG.md +1109 -0
- package/lib/third-party/arborist/LICENSE.md +20 -0
- package/lib/third-party/arborist/README.md +315 -0
- package/lib/third-party/arborist/lib/arborist/index.js +258 -0
- package/lib/third-party/arborist/lib/arborist/load-actual.js +605 -0
- package/lib/third-party/arborist/lib/arborist/load-virtual.js +300 -0
- package/lib/third-party/arborist/lib/bin-links.js +120 -0
- package/lib/third-party/arborist/lib/calc-dep-flags.js +130 -0
- package/lib/third-party/arborist/lib/case-insensitive-map.js +51 -0
- package/lib/third-party/arborist/lib/consistent-resolve.js +42 -0
- package/lib/third-party/arborist/lib/debug.js +50 -0
- package/lib/third-party/arborist/lib/dep-valid.js +190 -0
- package/lib/third-party/arborist/lib/edge.js +417 -0
- package/lib/third-party/arborist/lib/from-path.js +36 -0
- package/lib/third-party/arborist/lib/gather-dep-set.js +43 -0
- package/lib/third-party/arborist/lib/index.js +22 -0
- package/lib/third-party/arborist/lib/inventory.js +138 -0
- package/lib/third-party/arborist/lib/link.js +169 -0
- package/lib/third-party/arborist/lib/node.js +1673 -0
- package/lib/third-party/arborist/lib/npm-extension.js +45 -0
- package/lib/third-party/arborist/lib/override-resolves.js +11 -0
- package/lib/third-party/arborist/lib/override-set.js +319 -0
- package/lib/third-party/arborist/lib/package-extensions.js +289 -0
- package/lib/third-party/arborist/lib/printable.js +210 -0
- package/lib/third-party/arborist/lib/proc-log.js +30 -0
- package/lib/third-party/arborist/lib/realpath.js +100 -0
- package/lib/third-party/arborist/lib/relpath.js +4 -0
- package/lib/third-party/arborist/lib/shrinkwrap.js +1291 -0
- package/lib/third-party/arborist/lib/spec-from-lock.js +34 -0
- package/lib/third-party/arborist/lib/tree-check.js +165 -0
- package/lib/third-party/arborist/lib/validate-npm-package-name.js +107 -0
- package/lib/third-party/arborist/lib/version-from-tgz.js +51 -0
- package/lib/third-party/arborist/lib/yarn-lock.js +397 -0
- package/lib/validator/bomValidator.js +985 -0
- package/lib/validator/complianceEngine.js +241 -0
- package/lib/validator/complianceRules.js +1680 -0
- package/lib/validator/generated/runtime.mjs +17 -0
- package/lib/validator/generated/validate-1.6.mjs +21258 -0
- package/lib/validator/generated/validate-1.7.mjs +24803 -0
- package/lib/validator/generated/validate-2.0.mjs +22931 -0
- package/lib/validator/index.js +246 -0
- package/lib/validator/reporters/annotations.js +142 -0
- package/lib/validator/reporters/console.js +160 -0
- package/lib/validator/reporters/index.js +41 -0
- package/lib/validator/reporters/json.js +37 -0
- package/lib/validator/reporters/sarif.js +184 -0
- package/package.json +209 -26
- package/types/bin/audit.d.ts +3 -0
- package/types/bin/audit.d.ts.map +1 -0
- package/types/bin/cdxgen.d.ts +3 -0
- package/types/bin/cdxgen.d.ts.map +1 -0
- package/types/bin/convert.d.ts +3 -0
- package/types/bin/convert.d.ts.map +1 -0
- package/types/bin/evinse.d.ts +3 -0
- package/types/bin/evinse.d.ts.map +1 -0
- package/types/bin/hbom.d.ts +3 -0
- package/types/bin/hbom.d.ts.map +1 -0
- package/types/bin/repl.d.ts +3 -0
- package/types/bin/repl.d.ts.map +1 -0
- package/types/bin/sign.d.ts +3 -0
- package/types/bin/sign.d.ts.map +1 -0
- package/types/bin/tracebom.d.ts +3 -0
- package/types/bin/tracebom.d.ts.map +1 -0
- package/types/bin/validate.d.ts +14 -0
- package/types/bin/validate.d.ts.map +1 -0
- package/types/bin/verify.d.ts +3 -0
- package/types/bin/verify.d.ts.map +1 -0
- package/types/lib/audit/index.d.ts +153 -0
- package/types/lib/audit/index.d.ts.map +1 -0
- package/types/lib/audit/progress.d.ts +31 -0
- package/types/lib/audit/progress.d.ts.map +1 -0
- package/types/lib/audit/reporters.d.ts +62 -0
- package/types/lib/audit/reporters.d.ts.map +1 -0
- package/types/lib/audit/scoring.d.ts +36 -0
- package/types/lib/audit/scoring.d.ts.map +1 -0
- package/types/lib/audit/targets.d.ts +77 -0
- package/types/lib/audit/targets.d.ts.map +1 -0
- package/types/lib/cli/bomAssembly.d.ts +315 -0
- package/types/lib/cli/bomAssembly.d.ts.map +1 -0
- package/types/lib/cli/cliOptions.d.ts +156 -0
- package/types/lib/cli/cliOptions.d.ts.map +1 -0
- package/types/lib/cli/index.d.ts +107 -0
- package/types/lib/cli/index.d.ts.map +1 -0
- package/types/lib/cli/jsBom.d.ts +94 -0
- package/types/lib/cli/jsBom.d.ts.map +1 -0
- package/types/lib/cli/jvmBom.d.ts +54 -0
- package/types/lib/cli/jvmBom.d.ts.map +1 -0
- package/types/lib/cli/managedBom.d.ts +105 -0
- package/types/lib/cli/managedBom.d.ts.map +1 -0
- package/types/lib/cli/nativeBom.d.ts +143 -0
- package/types/lib/cli/nativeBom.d.ts.map +1 -0
- package/types/lib/core/activity.d.ts +178 -0
- package/types/lib/core/activity.d.ts.map +1 -0
- package/types/lib/core/env.d.ts +192 -0
- package/types/lib/core/env.d.ts.map +1 -0
- package/types/lib/core/fs.d.ts +158 -0
- package/types/lib/core/fs.d.ts.map +1 -0
- package/types/lib/core/httpClient.d.ts +149 -0
- package/types/lib/core/httpClient.d.ts.map +1 -0
- package/types/lib/core/logger.d.ts +28 -0
- package/types/lib/core/logger.d.ts.map +1 -0
- package/types/lib/core/parallel.d.ts +95 -0
- package/types/lib/core/parallel.d.ts.map +1 -0
- package/types/lib/core/paths.d.ts +36 -0
- package/types/lib/core/paths.d.ts.map +1 -0
- package/types/lib/core/projectConfig.d.ts +23 -0
- package/types/lib/core/projectConfig.d.ts.map +1 -0
- package/types/lib/core/propertySanitizer.d.ts +23 -0
- package/types/lib/core/propertySanitizer.d.ts.map +1 -0
- package/types/lib/core/spdx.d.ts +5 -0
- package/types/lib/core/spdx.d.ts.map +1 -0
- package/types/lib/core/state.d.ts +20 -0
- package/types/lib/core/state.d.ts.map +1 -0
- package/types/lib/core/text.d.ts +78 -0
- package/types/lib/core/text.d.ts.map +1 -0
- package/types/lib/core/ui.d.ts +87 -0
- package/types/lib/core/ui.d.ts.map +1 -0
- package/types/lib/core/urls.d.ts +43 -0
- package/types/lib/core/urls.d.ts.map +1 -0
- package/types/lib/ecosystems/asarutils.d.ts +71 -0
- package/types/lib/ecosystems/asarutils.d.ts.map +1 -0
- package/types/lib/ecosystems/bunutils.d.ts +38 -0
- package/types/lib/ecosystems/bunutils.d.ts.map +1 -0
- package/types/lib/ecosystems/caxa.d.ts +8 -0
- package/types/lib/ecosystems/caxa.d.ts.map +1 -0
- package/types/lib/ecosystems/chromextutils.d.ts +97 -0
- package/types/lib/ecosystems/chromextutils.d.ts.map +1 -0
- package/types/lib/ecosystems/cmakeResolver.d.ts +176 -0
- package/types/lib/ecosystems/cmakeResolver.d.ts.map +1 -0
- package/types/lib/ecosystems/cppEvidence.d.ts +35 -0
- package/types/lib/ecosystems/cppEvidence.d.ts.map +1 -0
- package/types/lib/ecosystems/denoutils.d.ts +76 -0
- package/types/lib/ecosystems/denoutils.d.ts.map +1 -0
- package/types/lib/ecosystems/dotnetutils.d.ts +45 -0
- package/types/lib/ecosystems/dotnetutils.d.ts.map +1 -0
- package/types/lib/ecosystems/ecosystems.d.ts +279 -0
- package/types/lib/ecosystems/ecosystems.d.ts.map +1 -0
- package/types/lib/ecosystems/golem.d.ts +60 -0
- package/types/lib/ecosystems/golem.d.ts.map +1 -0
- package/types/lib/ecosystems/gradleutils.d.ts +139 -0
- package/types/lib/ecosystems/gradleutils.d.ts.map +1 -0
- package/types/lib/ecosystems/jsEvidence.d.ts +17 -0
- package/types/lib/ecosystems/jsEvidence.d.ts.map +1 -0
- package/types/lib/ecosystems/npmutils.d.ts +183 -0
- package/types/lib/ecosystems/npmutils.d.ts.map +1 -0
- package/types/lib/ecosystems/parsers-bazel.d.ts +36 -0
- package/types/lib/ecosystems/parsers-bazel.d.ts.map +1 -0
- package/types/lib/ecosystems/parsers-dotnet.d.ts +116 -0
- package/types/lib/ecosystems/parsers-dotnet.d.ts.map +1 -0
- package/types/lib/ecosystems/parsers-gleam.d.ts +33 -0
- package/types/lib/ecosystems/parsers-gleam.d.ts.map +1 -0
- package/types/lib/ecosystems/parsers-go.d.ts +92 -0
- package/types/lib/ecosystems/parsers-go.d.ts.map +1 -0
- package/types/lib/ecosystems/parsers-js.d.ts +242 -0
- package/types/lib/ecosystems/parsers-js.d.ts.map +1 -0
- package/types/lib/ecosystems/parsers-jvm.d.ts +100 -0
- package/types/lib/ecosystems/parsers-jvm.d.ts.map +1 -0
- package/types/lib/ecosystems/parsers-misc.d.ts +450 -0
- package/types/lib/ecosystems/parsers-misc.d.ts.map +1 -0
- package/types/lib/ecosystems/parsers-python.d.ts +145 -0
- package/types/lib/ecosystems/parsers-python.d.ts.map +1 -0
- package/types/lib/ecosystems/parsers-rust.d.ts +56 -0
- package/types/lib/ecosystems/parsers-rust.d.ts.map +1 -0
- package/types/lib/ecosystems/parsers-zig.d.ts +83 -0
- package/types/lib/ecosystems/parsers-zig.d.ts.map +1 -0
- package/types/lib/ecosystems/pep770.d.ts +38 -0
- package/types/lib/ecosystems/pep770.d.ts.map +1 -0
- package/types/lib/ecosystems/pylockutils.d.ts +68 -0
- package/types/lib/ecosystems/pylockutils.d.ts.map +1 -0
- package/types/lib/ecosystems/pythonutils.d.ts +70 -0
- package/types/lib/ecosystems/pythonutils.d.ts.map +1 -0
- package/types/lib/ecosystems/registryProvenance.d.ts +26 -0
- package/types/lib/ecosystems/registryProvenance.d.ts.map +1 -0
- package/types/lib/ecosystems/remote/huggingface.d.ts +31 -0
- package/types/lib/ecosystems/remote/huggingface.d.ts.map +1 -0
- package/types/lib/ecosystems/rubyutils.d.ts +182 -0
- package/types/lib/ecosystems/rubyutils.d.ts.map +1 -0
- package/types/lib/ecosystems/rusi.d.ts +40 -0
- package/types/lib/ecosystems/rusi.d.ts.map +1 -0
- package/types/lib/ecosystems/sbtutils.d.ts +179 -0
- package/types/lib/ecosystems/sbtutils.d.ts.map +1 -0
- package/types/lib/ecosystems/tea.d.ts +180 -0
- package/types/lib/ecosystems/tea.d.ts.map +1 -0
- package/types/lib/ecosystems/utils.d.ts +41 -0
- package/types/lib/ecosystems/utils.d.ts.map +1 -0
- package/types/lib/ecosystems/zigResolver.d.ts +70 -0
- package/types/lib/ecosystems/zigResolver.d.ts.map +1 -0
- package/types/lib/evinser/db.d.ts +17 -0
- package/types/lib/evinser/db.d.ts.map +1 -0
- package/types/lib/evinser/evinser.d.ts +354 -0
- package/types/lib/evinser/evinser.d.ts.map +1 -0
- package/types/lib/evinser/scalasem.d.ts +15 -0
- package/types/lib/evinser/scalasem.d.ts.map +1 -0
- package/types/lib/evinser/swiftsem.d.ts +103 -0
- package/types/lib/evinser/swiftsem.d.ts.map +1 -0
- package/types/lib/helpers/annotationFormatter.d.ts +23 -0
- package/types/lib/helpers/annotationFormatter.d.ts.map +1 -0
- package/types/lib/helpers/bomSigner.d.ts +28 -0
- package/types/lib/helpers/bomSigner.d.ts.map +1 -0
- package/types/lib/helpers/exportUtils.d.ts +52 -0
- package/types/lib/helpers/exportUtils.d.ts.map +1 -0
- package/types/lib/helpers/remote/dependency-track.d.ts +23 -0
- package/types/lib/helpers/remote/dependency-track.d.ts.map +1 -0
- package/types/lib/helpers/versutils.d.ts +8 -0
- package/types/lib/helpers/versutils.d.ts.map +1 -0
- package/types/lib/helpers/vsixutils.d.ts +130 -0
- package/types/lib/helpers/vsixutils.d.ts.map +1 -0
- package/types/lib/inventory/agentFormulationParser.d.ts +21 -0
- package/types/lib/inventory/agentFormulationParser.d.ts.map +1 -0
- package/types/lib/inventory/aiCollector.d.ts +61 -0
- package/types/lib/inventory/aiCollector.d.ts.map +1 -0
- package/types/lib/inventory/aiInventory.d.ts +103 -0
- package/types/lib/inventory/aiInventory.d.ts.map +1 -0
- package/types/lib/inventory/aiModelVariants.d.ts +31 -0
- package/types/lib/inventory/aiModelVariants.d.ts.map +1 -0
- package/types/lib/inventory/aiOversightCollector.d.ts +28 -0
- package/types/lib/inventory/aiOversightCollector.d.ts.map +1 -0
- package/types/lib/inventory/aiProvenanceCollector.d.ts +13 -0
- package/types/lib/inventory/aiProvenanceCollector.d.ts.map +1 -0
- package/types/lib/inventory/analyzer.d.ts +157 -0
- package/types/lib/inventory/analyzer.d.ts.map +1 -0
- package/types/lib/inventory/analyzerScope.d.ts +106 -0
- package/types/lib/inventory/analyzerScope.d.ts.map +1 -0
- package/types/lib/inventory/astWorker.d.ts +9 -0
- package/types/lib/inventory/astWorker.d.ts.map +1 -0
- package/types/lib/inventory/atomUtils.d.ts +159 -0
- package/types/lib/inventory/atomUtils.d.ts.map +1 -0
- package/types/lib/inventory/auditCategories.d.ts +80 -0
- package/types/lib/inventory/auditCategories.d.ts.map +1 -0
- package/types/lib/inventory/bomUtils.d.ts +145 -0
- package/types/lib/inventory/bomUtils.d.ts.map +1 -0
- package/types/lib/inventory/cacheCommands.d.ts +28 -0
- package/types/lib/inventory/cacheCommands.d.ts.map +1 -0
- package/types/lib/inventory/cacheDir.d.ts +55 -0
- package/types/lib/inventory/cacheDir.d.ts.map +1 -0
- package/types/lib/inventory/cbomutils.d.ts +37 -0
- package/types/lib/inventory/cbomutils.d.ts.map +1 -0
- package/types/lib/inventory/cdxrs.d.ts +90 -0
- package/types/lib/inventory/cdxrs.d.ts.map +1 -0
- package/types/lib/inventory/ciParsers/azurePipelines.d.ts +27 -0
- package/types/lib/inventory/ciParsers/azurePipelines.d.ts.map +1 -0
- package/types/lib/inventory/ciParsers/circleCi.d.ts +27 -0
- package/types/lib/inventory/ciParsers/circleCi.d.ts.map +1 -0
- package/types/lib/inventory/ciParsers/common.d.ts +11 -0
- package/types/lib/inventory/ciParsers/common.d.ts.map +1 -0
- package/types/lib/inventory/ciParsers/githubActions.d.ts +38 -0
- package/types/lib/inventory/ciParsers/githubActions.d.ts.map +1 -0
- package/types/lib/inventory/ciParsers/gitlabCi.d.ts +26 -0
- package/types/lib/inventory/ciParsers/gitlabCi.d.ts.map +1 -0
- package/types/lib/inventory/ciParsers/jenkins.d.ts +26 -0
- package/types/lib/inventory/ciParsers/jenkins.d.ts.map +1 -0
- package/types/lib/inventory/citations.d.ts +90 -0
- package/types/lib/inventory/citations.d.ts.map +1 -0
- package/types/lib/inventory/communityAiConfigParser.d.ts +14 -0
- package/types/lib/inventory/communityAiConfigParser.d.ts.map +1 -0
- package/types/lib/inventory/containerRisk.d.ts +20 -0
- package/types/lib/inventory/containerRisk.d.ts.map +1 -0
- package/types/lib/inventory/cryptoAlgorithmFamily.d.ts +37 -0
- package/types/lib/inventory/cryptoAlgorithmFamily.d.ts.map +1 -0
- package/types/lib/inventory/deps.d.ts +140 -0
- package/types/lib/inventory/deps.d.ts.map +1 -0
- package/types/lib/inventory/depsUtils.d.ts +74 -0
- package/types/lib/inventory/depsUtils.d.ts.map +1 -0
- package/types/lib/inventory/display.d.ts +227 -0
- package/types/lib/inventory/display.d.ts.map +1 -0
- package/types/lib/inventory/dosai.d.ts +130 -0
- package/types/lib/inventory/dosai.d.ts.map +1 -0
- package/types/lib/inventory/dosaiParsers.d.ts +59 -0
- package/types/lib/inventory/dosaiParsers.d.ts.map +1 -0
- package/types/lib/inventory/dynamic.d.ts +25 -0
- package/types/lib/inventory/dynamic.d.ts.map +1 -0
- package/types/lib/inventory/envcontext.d.ts +377 -0
- package/types/lib/inventory/envcontext.d.ts.map +1 -0
- package/types/lib/inventory/evidenceUtils.d.ts +74 -0
- package/types/lib/inventory/evidenceUtils.d.ts.map +1 -0
- package/types/lib/inventory/fetchBatch.d.ts +127 -0
- package/types/lib/inventory/fetchBatch.d.ts.map +1 -0
- package/types/lib/inventory/fetchRate.d.ts +118 -0
- package/types/lib/inventory/fetchRate.d.ts.map +1 -0
- package/types/lib/inventory/forgeEnricher.d.ts +31 -0
- package/types/lib/inventory/forgeEnricher.d.ts.map +1 -0
- package/types/lib/inventory/formulationParsers.d.ts +50 -0
- package/types/lib/inventory/formulationParsers.d.ts.map +1 -0
- package/types/lib/inventory/gtfobins.d.ts +27 -0
- package/types/lib/inventory/gtfobins.d.ts.map +1 -0
- package/types/lib/inventory/hbom.d.ts +58 -0
- package/types/lib/inventory/hbom.d.ts.map +1 -0
- package/types/lib/inventory/hbomAnalysis.d.ts +56 -0
- package/types/lib/inventory/hbomAnalysis.d.ts.map +1 -0
- package/types/lib/inventory/hbomLoader.d.ts +7 -0
- package/types/lib/inventory/hbomLoader.d.ts.map +1 -0
- package/types/lib/inventory/hostTopology.d.ts +47 -0
- package/types/lib/inventory/hostTopology.d.ts.map +1 -0
- package/types/lib/inventory/inventoryStats.d.ts +42 -0
- package/types/lib/inventory/inventoryStats.d.ts.map +1 -0
- package/types/lib/inventory/jsonLike.d.ts +23 -0
- package/types/lib/inventory/jsonLike.d.ts.map +1 -0
- package/types/lib/inventory/licenseEnhancer.d.ts +70 -0
- package/types/lib/inventory/licenseEnhancer.d.ts.map +1 -0
- package/types/lib/inventory/lolbas.d.ts +16 -0
- package/types/lib/inventory/lolbas.d.ts.map +1 -0
- package/types/lib/inventory/mcp.d.ts +29 -0
- package/types/lib/inventory/mcp.d.ts.map +1 -0
- package/types/lib/inventory/mcpConfigParser.d.ts +20 -0
- package/types/lib/inventory/mcpConfigParser.d.ts.map +1 -0
- package/types/lib/inventory/mcpDiscovery.d.ts +33 -0
- package/types/lib/inventory/mcpDiscovery.d.ts.map +1 -0
- package/types/lib/inventory/mcpPinning.d.ts +11 -0
- package/types/lib/inventory/mcpPinning.d.ts.map +1 -0
- package/types/lib/inventory/osPackageResolver.d.ts +49 -0
- package/types/lib/inventory/osPackageResolver.d.ts.map +1 -0
- package/types/lib/inventory/osinfo.d.ts +120 -0
- package/types/lib/inventory/osinfo.d.ts.map +1 -0
- package/types/lib/inventory/osqueryTransform.d.ts +84 -0
- package/types/lib/inventory/osqueryTransform.d.ts.map +1 -0
- package/types/lib/inventory/plugins.d.ts +58 -0
- package/types/lib/inventory/plugins.d.ts.map +1 -0
- package/types/lib/inventory/protobom.d.ts +71 -0
- package/types/lib/inventory/protobom.d.ts.map +1 -0
- package/types/lib/inventory/protobomLoader.d.ts +17 -0
- package/types/lib/inventory/protobomLoader.d.ts.map +1 -0
- package/types/lib/inventory/provenanceUtils.d.ts +98 -0
- package/types/lib/inventory/provenanceUtils.d.ts.map +1 -0
- package/types/lib/inventory/purl.d.ts +313 -0
- package/types/lib/inventory/purl.d.ts.map +1 -0
- package/types/lib/inventory/rustFormulationParser.d.ts +17 -0
- package/types/lib/inventory/rustFormulationParser.d.ts.map +1 -0
- package/types/lib/inventory/sbomDocument.d.ts +59 -0
- package/types/lib/inventory/sbomDocument.d.ts.map +1 -0
- package/types/lib/inventory/source.d.ts +163 -0
- package/types/lib/inventory/source.d.ts.map +1 -0
- package/types/lib/inventory/spdx.d.ts +66 -0
- package/types/lib/inventory/spdx.d.ts.map +1 -0
- package/types/lib/inventory/spdxExpression.d.ts +58 -0
- package/types/lib/inventory/spdxExpression.d.ts.map +1 -0
- package/types/lib/inventory/spdxUtils.d.ts +12 -0
- package/types/lib/inventory/spdxUtils.d.ts.map +1 -0
- package/types/lib/inventory/table.d.ts +19 -0
- package/types/lib/inventory/table.d.ts.map +1 -0
- package/types/lib/inventory/traceRunner.d.ts +80 -0
- package/types/lib/inventory/traceRunner.d.ts.map +1 -0
- package/types/lib/inventory/unicodeScan.d.ts +46 -0
- package/types/lib/inventory/unicodeScan.d.ts.map +1 -0
- package/types/lib/managers/binary.d.ts +76 -0
- package/types/lib/managers/binary.d.ts.map +1 -0
- package/types/lib/managers/containerutils.d.ts +30 -0
- package/types/lib/managers/containerutils.d.ts.map +1 -0
- package/types/lib/managers/docker.d.ts +157 -0
- package/types/lib/managers/docker.d.ts.map +1 -0
- package/types/lib/managers/dockerConnection.d.ts +42 -0
- package/types/lib/managers/dockerConnection.d.ts.map +1 -0
- package/types/lib/managers/oci.d.ts +21 -0
- package/types/lib/managers/oci.d.ts.map +1 -0
- package/types/lib/managers/piptree.d.ts +13 -0
- package/types/lib/managers/piptree.d.ts.map +1 -0
- package/types/lib/parsers/cmakeCache.d.ts +70 -0
- package/types/lib/parsers/cmakeCache.d.ts.map +1 -0
- package/types/lib/parsers/gguf.d.ts +39 -0
- package/types/lib/parsers/gguf.d.ts.map +1 -0
- package/types/lib/parsers/gitAiNotes.d.ts +15 -0
- package/types/lib/parsers/gitAiNotes.d.ts.map +1 -0
- package/types/lib/parsers/gitmodules.d.ts +88 -0
- package/types/lib/parsers/gitmodules.d.ts.map +1 -0
- package/types/lib/parsers/htmlExtract.d.ts +34 -0
- package/types/lib/parsers/htmlExtract.d.ts.map +1 -0
- package/types/lib/parsers/huggingfaceManifest.d.ts +153 -0
- package/types/lib/parsers/huggingfaceManifest.d.ts.map +1 -0
- package/types/lib/parsers/huggingfaceUtils.d.ts +155 -0
- package/types/lib/parsers/huggingfaceUtils.d.ts.map +1 -0
- package/types/lib/parsers/iri.d.ts +68 -0
- package/types/lib/parsers/iri.d.ts.map +1 -0
- package/types/lib/parsers/npmrc.d.ts +33 -0
- package/types/lib/parsers/npmrc.d.ts.map +1 -0
- package/types/lib/parsers/ollama.d.ts +22 -0
- package/types/lib/parsers/ollama.d.ts.map +1 -0
- package/types/lib/parsers/xml.d.ts +47 -0
- package/types/lib/parsers/xml.d.ts.map +1 -0
- package/types/lib/server/server.d.ts +51 -0
- package/types/lib/server/server.d.ts.map +1 -0
- package/types/lib/stages/postgen/annotator.d.ts +36 -0
- package/types/lib/stages/postgen/annotator.d.ts.map +1 -0
- package/types/lib/stages/postgen/auditBom.d.ts +92 -0
- package/types/lib/stages/postgen/auditBom.d.ts.map +1 -0
- package/types/lib/stages/postgen/postgen.d.ts +59 -0
- package/types/lib/stages/postgen/postgen.d.ts.map +1 -0
- package/types/lib/stages/postgen/ruleEngine.d.ts +18 -0
- package/types/lib/stages/postgen/ruleEngine.d.ts.map +1 -0
- package/types/lib/stages/postgen/sortBom.d.ts +34 -0
- package/types/lib/stages/postgen/sortBom.d.ts.map +1 -0
- package/types/lib/stages/postgen/spdxConverter.d.ts +11 -0
- package/types/lib/stages/postgen/spdxConverter.d.ts.map +1 -0
- package/types/lib/stages/postgen/specVersionCompat.d.ts +71 -0
- package/types/lib/stages/postgen/specVersionCompat.d.ts.map +1 -0
- package/types/lib/stages/pregen/envAudit.d.ts +14 -0
- package/types/lib/stages/pregen/envAudit.d.ts.map +1 -0
- package/types/lib/stages/pregen/pregen.d.ts +59 -0
- package/types/lib/stages/pregen/pregen.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/arborist/index.d.ts +47 -0
- package/types/lib/third-party/arborist/lib/arborist/index.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/arborist/load-actual.d.ts +4 -0
- package/types/lib/third-party/arborist/lib/arborist/load-actual.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/arborist/load-virtual.d.ts +4 -0
- package/types/lib/third-party/arborist/lib/arborist/load-virtual.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/bin-links.d.ts +18 -0
- package/types/lib/third-party/arborist/lib/bin-links.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/calc-dep-flags.d.ts +3 -0
- package/types/lib/third-party/arborist/lib/calc-dep-flags.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/case-insensitive-map.d.ts +9 -0
- package/types/lib/third-party/arborist/lib/case-insensitive-map.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/consistent-resolve.d.ts +3 -0
- package/types/lib/third-party/arborist/lib/consistent-resolve.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/debug.d.ts +3 -0
- package/types/lib/third-party/arborist/lib/debug.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/dep-valid.d.ts +3 -0
- package/types/lib/third-party/arborist/lib/dep-valid.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/edge.d.ts +46 -0
- package/types/lib/third-party/arborist/lib/edge.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/from-path.d.ts +3 -0
- package/types/lib/third-party/arborist/lib/from-path.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/gather-dep-set.d.ts +3 -0
- package/types/lib/third-party/arborist/lib/gather-dep-set.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/index.d.ts +3 -0
- package/types/lib/third-party/arborist/lib/index.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/inventory.d.ts +14 -0
- package/types/lib/third-party/arborist/lib/inventory.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/link.d.ts +18 -0
- package/types/lib/third-party/arborist/lib/link.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/node.d.ts +112 -0
- package/types/lib/third-party/arborist/lib/node.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/npm-extension.d.ts +18 -0
- package/types/lib/third-party/arborist/lib/npm-extension.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/override-resolves.d.ts +3 -0
- package/types/lib/third-party/arborist/lib/override-resolves.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/override-set.d.ts +27 -0
- package/types/lib/third-party/arborist/lib/override-set.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/package-extensions.d.ts +36 -0
- package/types/lib/third-party/arborist/lib/package-extensions.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/printable.d.ts +3 -0
- package/types/lib/third-party/arborist/lib/printable.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/proc-log.d.ts +20 -0
- package/types/lib/third-party/arborist/lib/proc-log.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/realpath.d.ts +3 -0
- package/types/lib/third-party/arborist/lib/realpath.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/relpath.d.ts +3 -0
- package/types/lib/third-party/arborist/lib/relpath.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/shrinkwrap.d.ts +54 -0
- package/types/lib/third-party/arborist/lib/shrinkwrap.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/spec-from-lock.d.ts +3 -0
- package/types/lib/third-party/arborist/lib/spec-from-lock.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/tree-check.d.ts +3 -0
- package/types/lib/third-party/arborist/lib/tree-check.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/validate-npm-package-name.d.ts +13 -0
- package/types/lib/third-party/arborist/lib/validate-npm-package-name.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/version-from-tgz.d.ts +6 -0
- package/types/lib/third-party/arborist/lib/version-from-tgz.d.ts.map +1 -0
- package/types/lib/third-party/arborist/lib/yarn-lock.d.ts +35 -0
- package/types/lib/third-party/arborist/lib/yarn-lock.d.ts.map +1 -0
- package/types/lib/validator/bomValidator.d.ts +40 -0
- package/types/lib/validator/bomValidator.d.ts.map +1 -0
- package/types/lib/validator/complianceEngine.d.ts +72 -0
- package/types/lib/validator/complianceEngine.d.ts.map +1 -0
- package/types/lib/validator/complianceRules.d.ts +61 -0
- package/types/lib/validator/complianceRules.d.ts.map +1 -0
- package/types/lib/validator/index.d.ts +101 -0
- package/types/lib/validator/index.d.ts.map +1 -0
- package/types/lib/validator/reporters/annotations.d.ts +37 -0
- package/types/lib/validator/reporters/annotations.d.ts.map +1 -0
- package/types/lib/validator/reporters/console.d.ts +34 -0
- package/types/lib/validator/reporters/console.d.ts.map +1 -0
- package/types/lib/validator/reporters/index.d.ts +30 -0
- package/types/lib/validator/reporters/index.d.ts.map +1 -0
- package/types/lib/validator/reporters/json.d.ts +11 -0
- package/types/lib/validator/reporters/json.d.ts.map +1 -0
- package/types/lib/validator/reporters/sarif.d.ts +22 -0
- package/types/lib/validator/reporters/sarif.d.ts.map +1 -0
- package/mod.d.ts +0 -7
- package/mod.js +0 -22
|
@@ -0,0 +1,2140 @@
|
|
|
1
|
+
import { readFileSync, statSync } from "node:fs";
|
|
2
|
+
import { basename, dirname, extname, relative } from "node:path";
|
|
3
|
+
|
|
4
|
+
import { getAllFiles } from "../core/fs.js";
|
|
5
|
+
import {
|
|
6
|
+
sanitizeBomPropertyValue,
|
|
7
|
+
sanitizeBomUrl,
|
|
8
|
+
sanitizeStructuredValueForBom,
|
|
9
|
+
} from "../core/propertySanitizer.js";
|
|
10
|
+
import {
|
|
11
|
+
ggufFileTypeName,
|
|
12
|
+
parseGgufFilename,
|
|
13
|
+
readGgufMetadata,
|
|
14
|
+
} from "../parsers/gguf.js";
|
|
15
|
+
import {
|
|
16
|
+
createHuggingFaceDatasetReference,
|
|
17
|
+
createHuggingFaceModelCard,
|
|
18
|
+
createHuggingFacePedigree,
|
|
19
|
+
HUGGING_FACE_ADAPTER_PATTERNS,
|
|
20
|
+
HUGGING_FACE_CONFIG_PATTERNS,
|
|
21
|
+
HUGGING_FACE_MODEL_CARD_PATTERNS,
|
|
22
|
+
hasHuggingFaceCardSignals,
|
|
23
|
+
parseHuggingFaceReadmeFrontmatter,
|
|
24
|
+
repoIdFromFixtureDirectory,
|
|
25
|
+
} from "../parsers/huggingfaceManifest.js";
|
|
26
|
+
import {
|
|
27
|
+
normalizeHuggingFaceReference,
|
|
28
|
+
quantizationValueFromConfig,
|
|
29
|
+
repositoryUrlForHuggingFaceAssetType,
|
|
30
|
+
toHuggingFaceAssetUrl,
|
|
31
|
+
toHuggingFacePurl,
|
|
32
|
+
} from "../parsers/huggingfaceUtils.js";
|
|
33
|
+
import { parseOllamaModelfile } from "../parsers/ollama.js";
|
|
34
|
+
import {
|
|
35
|
+
detectAiModelVariants,
|
|
36
|
+
normalizeDetectedVariants,
|
|
37
|
+
} from "./aiModelVariants.js";
|
|
38
|
+
import { getLicenses } from "./spdx.js";
|
|
39
|
+
|
|
40
|
+
// -----------------------------------------------------------------------------
|
|
41
|
+
// Section: source patterns, provider fingerprints, and low-level constants
|
|
42
|
+
// -----------------------------------------------------------------------------
|
|
43
|
+
|
|
44
|
+
const JS_SOURCE_PATTERNS = ["**/*.{js,jsx,cjs,mjs,ts,tsx,mts,cts,vue,svelte}"];
|
|
45
|
+
const PYTHON_SOURCE_PATTERNS = ["**/*.{py,pyw}"];
|
|
46
|
+
const NOTEBOOK_SOURCE_PATTERNS = ["**/*.ipynb"];
|
|
47
|
+
const SHELL_WRAPPER_PATTERNS = ["**/*.{sh,bash,zsh,command}"];
|
|
48
|
+
const PROMPT_CONFIG_PATTERNS = [
|
|
49
|
+
"**/*.{prompt,prompt.txt,prompt.md}",
|
|
50
|
+
"**/{prompt,prompts,agents,ai,assistant,instructions}/**/*.{md,txt,json,jsonc,yaml,yml,toml}",
|
|
51
|
+
"**/*{prompt,prompts,instruction,instructions,assistant,system,persona,agent,model}*.{md,txt,json,jsonc,yaml,yml,toml}",
|
|
52
|
+
];
|
|
53
|
+
const MODEFILE_PATTERNS = ["Modelfile", "**/Modelfile", "**/Modelfile.*"];
|
|
54
|
+
const GGUF_PATTERNS = ["**/*.gguf"];
|
|
55
|
+
const GGUF_MIN_ALIGNMENT = 4;
|
|
56
|
+
const GGUF_MAX_ALIGNMENT = 1024 * 1024;
|
|
57
|
+
const IGNORE_SOURCE_FILE_PATTERN =
|
|
58
|
+
/(^|\/|\\)(__tests__|fixtures?|examples?|samples?)($|\/|\\)|(^|\/|\\)(test|spec|mock|setup-jest|conftest|sitecustomize)\.(js|ts|tsx|py)$|(?<!vite\.|vue\.)(conf|config)\.(js|ts|tsx)$/iu;
|
|
59
|
+
const HOST_PROVIDER_PATTERNS = [
|
|
60
|
+
["openai", /(?:^|\.)openai\.com$/iu],
|
|
61
|
+
["anthropic", /(?:^|\.)anthropic\.com$/iu],
|
|
62
|
+
["google", /(?:^|\.)googleapis\.com$/iu],
|
|
63
|
+
["google", /(?:^|\.)generativelanguage\.googleapis\.com$/iu],
|
|
64
|
+
["azure-openai", /(?:^|\.)openai\.azure\.com$/iu],
|
|
65
|
+
["huggingface", /(?:^|\.)huggingface\.co$/iu],
|
|
66
|
+
["mistral", /(?:^|\.)mistral\.ai$/iu],
|
|
67
|
+
["cohere", /(?:^|\.)cohere\.ai$/iu],
|
|
68
|
+
["deepseek", /(?:^|\.)deepseek\.com$/iu],
|
|
69
|
+
["groq", /(?:^|\.)groq\.com$/iu],
|
|
70
|
+
["fireworks", /(?:^|\.)fireworks\.ai$/iu],
|
|
71
|
+
["together", /(?:^|\.)together\.xyz$/iu],
|
|
72
|
+
["replicate", /(?:^|\.)replicate\.com$/iu],
|
|
73
|
+
["perplexity", /(?:^|\.)perplexity\.ai$/iu],
|
|
74
|
+
["vertex-ai", /(?:^|\.)aiplatform\.googleapis\.com$/iu],
|
|
75
|
+
["ollama", /(?:^|\.)ollama\.com$/iu],
|
|
76
|
+
["ollama", /(?:^|\.)localhost$/iu],
|
|
77
|
+
["ollama", /(?:^|\.)127\.0\.0\.1$/iu],
|
|
78
|
+
];
|
|
79
|
+
const AI_PACKAGE_REGISTRY = [
|
|
80
|
+
{ pattern: /^openai$/u, provider: "openai", serviceName: "OpenAI API" },
|
|
81
|
+
{
|
|
82
|
+
pattern: /^@anthropic-ai\/sdk$/u,
|
|
83
|
+
provider: "anthropic",
|
|
84
|
+
serviceName: "Anthropic API",
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
pattern: /^@google\/genai$/u,
|
|
88
|
+
provider: "google",
|
|
89
|
+
serviceName: "Google Generative AI API",
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
pattern: /^@google-ai\/generativelanguage$/u,
|
|
93
|
+
provider: "google",
|
|
94
|
+
serviceName: "Google Generative AI API",
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
pattern: /^@azure\/openai$/u,
|
|
98
|
+
provider: "azure-openai",
|
|
99
|
+
serviceName: "Azure OpenAI API",
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
pattern: /^@huggingface\/inference$/u,
|
|
103
|
+
provider: "huggingface",
|
|
104
|
+
serviceName: "Hugging Face Inference API",
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
pattern: /^@huggingface\/transformers$/u,
|
|
108
|
+
provider: "huggingface",
|
|
109
|
+
runtime: "transformers.js",
|
|
110
|
+
},
|
|
111
|
+
{ pattern: /^langchain$/u, framework: "langchain" },
|
|
112
|
+
{ pattern: /^@langchain\//u, framework: "langchain" },
|
|
113
|
+
{ pattern: /^langgraph$/u, framework: "langgraph" },
|
|
114
|
+
{ pattern: /^@langchain\/langgraph$/u, framework: "langgraph" },
|
|
115
|
+
{ pattern: /^ai$/u, framework: "vercel-ai-sdk" },
|
|
116
|
+
{ pattern: /^@ai-sdk\//u, framework: "vercel-ai-sdk" },
|
|
117
|
+
{
|
|
118
|
+
pattern: /^@openai\/agents(?:-core)?$/u,
|
|
119
|
+
framework: "openai-agents",
|
|
120
|
+
provider: "openai",
|
|
121
|
+
serviceName: "OpenAI API",
|
|
122
|
+
},
|
|
123
|
+
{ pattern: /^mastra$/u, framework: "mastra" },
|
|
124
|
+
{ pattern: /^ollama$/u, provider: "ollama", runtime: "ollama" },
|
|
125
|
+
{ pattern: /^node-llama-cpp$/u, runtime: "llama.cpp" },
|
|
126
|
+
{ pattern: /^@mlc-ai\//u, runtime: "mlc" },
|
|
127
|
+
{ pattern: /^groq-sdk$|^groq$/u, provider: "groq", serviceName: "Groq API" },
|
|
128
|
+
{
|
|
129
|
+
pattern: /^cohere-ai$/u,
|
|
130
|
+
provider: "cohere",
|
|
131
|
+
serviceName: "Cohere API",
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
pattern: /^@mistralai\/mistralai$/u,
|
|
135
|
+
provider: "mistral",
|
|
136
|
+
serviceName: "Mistral API",
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
pattern: /^@deepseek\/openai$/u,
|
|
140
|
+
provider: "deepseek",
|
|
141
|
+
serviceName: "DeepSeek API",
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
pattern: /^google-generativeai$|^google-genai$/u,
|
|
145
|
+
provider: "google",
|
|
146
|
+
serviceName: "Google Generative AI API",
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
pattern: /^anthropic$/u,
|
|
150
|
+
provider: "anthropic",
|
|
151
|
+
serviceName: "Anthropic API",
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
pattern: /^transformers$|^sentence-transformers$/u,
|
|
155
|
+
runtime: "transformers",
|
|
156
|
+
},
|
|
157
|
+
{ pattern: /^langchain_/u, framework: "langchain" },
|
|
158
|
+
{ pattern: /^llama-index(?:-|$)/u, framework: "llama-index" },
|
|
159
|
+
{ pattern: /^litellm$/u, framework: "litellm" },
|
|
160
|
+
{ pattern: /^autogen(?:-agentchat)?$/u, framework: "autogen" },
|
|
161
|
+
{ pattern: /^vllm$/u, runtime: "vllm" },
|
|
162
|
+
{
|
|
163
|
+
pattern: /^together$|^together-ai$/u,
|
|
164
|
+
provider: "together",
|
|
165
|
+
serviceName: "Together API",
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
pattern: /^fireworks-ai$/u,
|
|
169
|
+
provider: "fireworks",
|
|
170
|
+
serviceName: "Fireworks AI API",
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
pattern: /^replicate$/u,
|
|
174
|
+
provider: "replicate",
|
|
175
|
+
serviceName: "Replicate API",
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
pattern: /^perplexity(?:ai)?$/u,
|
|
179
|
+
provider: "perplexity",
|
|
180
|
+
serviceName: "Perplexity API",
|
|
181
|
+
},
|
|
182
|
+
];
|
|
183
|
+
const serializeAiService = (service) => ({
|
|
184
|
+
"bom-ref": service["bom-ref"],
|
|
185
|
+
group: service.group,
|
|
186
|
+
name: service.name,
|
|
187
|
+
provider: service.provider,
|
|
188
|
+
version: service.version,
|
|
189
|
+
endpoints: Array.from(service.endpoints)
|
|
190
|
+
.map((endpoint) => sanitizeBomUrl(endpoint))
|
|
191
|
+
.filter(Boolean)
|
|
192
|
+
.sort(),
|
|
193
|
+
properties: service.properties,
|
|
194
|
+
tags: Array.from(service.tags).sort(),
|
|
195
|
+
evidence: service.occurrences.length
|
|
196
|
+
? { occurrences: service.occurrences }
|
|
197
|
+
: undefined,
|
|
198
|
+
});
|
|
199
|
+
const TEXT_AI_INVENTORY_CONFIGS = {
|
|
200
|
+
javascript: { patterns: JS_SOURCE_PATTERNS },
|
|
201
|
+
notebook: {
|
|
202
|
+
fileKind: "notebook-file",
|
|
203
|
+
patterns: NOTEBOOK_SOURCE_PATTERNS,
|
|
204
|
+
tags: ["notebook"],
|
|
205
|
+
},
|
|
206
|
+
promptConfig: {
|
|
207
|
+
fileKind: "prompt-config-file",
|
|
208
|
+
patterns: [...SHELL_WRAPPER_PATTERNS, ...PROMPT_CONFIG_PATTERNS],
|
|
209
|
+
tags: ["prompt-config"],
|
|
210
|
+
},
|
|
211
|
+
python: { patterns: PYTHON_SOURCE_PATTERNS },
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
// -----------------------------------------------------------------------------
|
|
215
|
+
// Section: generic component, service, and text-scanning helpers
|
|
216
|
+
// -----------------------------------------------------------------------------
|
|
217
|
+
|
|
218
|
+
const addUniqueProperty = (properties, name, value) => {
|
|
219
|
+
const sanitizedValue = sanitizeBomPropertyValue(name, value);
|
|
220
|
+
if (
|
|
221
|
+
sanitizedValue === undefined ||
|
|
222
|
+
sanitizedValue === null ||
|
|
223
|
+
sanitizedValue === ""
|
|
224
|
+
) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
const normalizedValue = String(sanitizedValue);
|
|
228
|
+
if (
|
|
229
|
+
properties.some(
|
|
230
|
+
(property) =>
|
|
231
|
+
property?.name === name && property?.value === normalizedValue,
|
|
232
|
+
)
|
|
233
|
+
) {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
properties.push({ name, value: normalizedValue });
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
const linePrefixForIndex = (raw, index) => {
|
|
240
|
+
const lineStart = raw.lastIndexOf("\n", index - 1) + 1;
|
|
241
|
+
return raw.slice(lineStart, index).trim();
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
const extractImportNames = (raw) => {
|
|
245
|
+
const imports = [];
|
|
246
|
+
for (const match of raw.matchAll(
|
|
247
|
+
/(?:import\s+(?:.+?\s+from\s+)?|require\(\s*)["'`]([^"'`]+)["'`]/gu,
|
|
248
|
+
)) {
|
|
249
|
+
if (linePrefixForIndex(raw, match.index) !== "") {
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
imports.push({ index: match.index, names: [match[1]] });
|
|
253
|
+
}
|
|
254
|
+
for (const match of raw.matchAll(
|
|
255
|
+
/from\s+([A-Za-z0-9_.-]+)\s+import\b|import\s+([A-Za-z0-9_.,\s-]+)/gu,
|
|
256
|
+
)) {
|
|
257
|
+
if (linePrefixForIndex(raw, match.index) !== "") {
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
const modules = match[1]
|
|
261
|
+
? [match[1]]
|
|
262
|
+
: String(match[2] || "")
|
|
263
|
+
.split(",")
|
|
264
|
+
.map((entry) => entry.trim().split(/\s+as\s+/u)[0])
|
|
265
|
+
.filter(Boolean);
|
|
266
|
+
if (modules.length) {
|
|
267
|
+
imports.push({ index: match.index, names: modules });
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
return imports;
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
const createFileSignals = () => ({
|
|
274
|
+
fileRef: undefined,
|
|
275
|
+
frameworks: new Set(),
|
|
276
|
+
modelRefs: new Set(),
|
|
277
|
+
providers: new Set(),
|
|
278
|
+
runtimes: new Set(),
|
|
279
|
+
serviceRefs: new Set(),
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
const relativeOccurrenceLocation = (discoveryPath, filePath, lineNumber) => {
|
|
283
|
+
const relativePath = relative(discoveryPath, filePath) || basename(filePath);
|
|
284
|
+
return lineNumber ? `${relativePath}#L${lineNumber}` : relativePath;
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
const appendOccurrence = (target, location) => {
|
|
288
|
+
target.occurrences = target.occurrences || [];
|
|
289
|
+
if (!target.occurrences.some((entry) => entry.location === location)) {
|
|
290
|
+
target.occurrences.push({ location });
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
const mergePedigreeVariants = (pedigree, variants = []) => {
|
|
295
|
+
const normalizedVariants = normalizeDetectedVariants(variants);
|
|
296
|
+
if (!pedigree && !normalizedVariants.length) {
|
|
297
|
+
return pedigree;
|
|
298
|
+
}
|
|
299
|
+
const nextPedigree = pedigree ? { ...pedigree } : {};
|
|
300
|
+
const notes = [];
|
|
301
|
+
if (nextPedigree.notes) {
|
|
302
|
+
notes.push(String(nextPedigree.notes));
|
|
303
|
+
}
|
|
304
|
+
if (normalizedVariants.length) {
|
|
305
|
+
notes.push(`Detected variants: ${normalizedVariants.join(", ")}`);
|
|
306
|
+
}
|
|
307
|
+
if (notes.length) {
|
|
308
|
+
nextPedigree.notes = [...new Set(notes)].join("; ");
|
|
309
|
+
}
|
|
310
|
+
return Object.keys(nextPedigree).length ? nextPedigree : undefined;
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
const lineNumberForIndex = (text, index) =>
|
|
314
|
+
text.slice(0, index).split("\n").length;
|
|
315
|
+
|
|
316
|
+
const isLocalAiHostname = (hostname) => {
|
|
317
|
+
const normalized = String(hostname || "").toLowerCase();
|
|
318
|
+
return (
|
|
319
|
+
normalized === "localhost" ||
|
|
320
|
+
normalized === "127.0.0.1" ||
|
|
321
|
+
normalized === "::1" ||
|
|
322
|
+
normalized.endsWith(".localhost")
|
|
323
|
+
);
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
const hostProviderFromValue = (urlValue) => {
|
|
327
|
+
try {
|
|
328
|
+
const parsed = new URL(urlValue);
|
|
329
|
+
return (
|
|
330
|
+
HOST_PROVIDER_PATTERNS.find(([, pattern]) =>
|
|
331
|
+
pattern.test(parsed.hostname),
|
|
332
|
+
)?.[0] || undefined
|
|
333
|
+
);
|
|
334
|
+
} catch {
|
|
335
|
+
return undefined;
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
const modelFamilyFromName = (modelName) => {
|
|
340
|
+
const normalized = String(modelName || "").toLowerCase();
|
|
341
|
+
if (!normalized) {
|
|
342
|
+
return undefined;
|
|
343
|
+
}
|
|
344
|
+
if (normalized.includes("claude")) {
|
|
345
|
+
return "claude";
|
|
346
|
+
}
|
|
347
|
+
if (normalized.includes("gpt") || /^o[13](?:$|[-:])/u.test(normalized)) {
|
|
348
|
+
return "gpt";
|
|
349
|
+
}
|
|
350
|
+
if (normalized.includes("gemini")) {
|
|
351
|
+
return "gemini";
|
|
352
|
+
}
|
|
353
|
+
if (normalized.includes("llama")) {
|
|
354
|
+
return "llama";
|
|
355
|
+
}
|
|
356
|
+
if (normalized.includes("mistral")) {
|
|
357
|
+
return "mistral";
|
|
358
|
+
}
|
|
359
|
+
if (normalized.includes("command")) {
|
|
360
|
+
return "command";
|
|
361
|
+
}
|
|
362
|
+
if (normalized.includes("deepseek")) {
|
|
363
|
+
return "deepseek";
|
|
364
|
+
}
|
|
365
|
+
if (normalized.includes("qwen")) {
|
|
366
|
+
return "qwen";
|
|
367
|
+
}
|
|
368
|
+
return normalized.split(/[/:,\-]/u)[0] || undefined;
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
const providerFromModelName = (modelName) => {
|
|
372
|
+
const normalized = String(modelName || "").toLowerCase();
|
|
373
|
+
if (normalized.includes("claude")) {
|
|
374
|
+
return "anthropic";
|
|
375
|
+
}
|
|
376
|
+
if (normalized.includes("gpt") || /^o[13](?:$|[-:])/u.test(normalized)) {
|
|
377
|
+
return "openai";
|
|
378
|
+
}
|
|
379
|
+
if (normalized.includes("gemini")) {
|
|
380
|
+
return "google";
|
|
381
|
+
}
|
|
382
|
+
if (normalized.includes("mistral")) {
|
|
383
|
+
return "mistral";
|
|
384
|
+
}
|
|
385
|
+
if (normalized.includes("deepseek")) {
|
|
386
|
+
return "deepseek";
|
|
387
|
+
}
|
|
388
|
+
if (normalized.includes("llama")) {
|
|
389
|
+
return "meta";
|
|
390
|
+
}
|
|
391
|
+
return undefined;
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
const parseJsonObject = (filePath) => {
|
|
395
|
+
try {
|
|
396
|
+
return JSON.parse(readFileSync(filePath, "utf-8"));
|
|
397
|
+
} catch {
|
|
398
|
+
return undefined;
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
const stableAiBomRef = (assetType, provider, identifier) =>
|
|
403
|
+
`cdxgen:ai:${assetType}:${provider}:${String(identifier || "").replaceAll(/[^a-zA-Z0-9._:-]+/gu, "-")}`;
|
|
404
|
+
|
|
405
|
+
// -----------------------------------------------------------------------------
|
|
406
|
+
// Section: Hugging Face pedigree, dataset, and model-card helpers
|
|
407
|
+
// -----------------------------------------------------------------------------
|
|
408
|
+
|
|
409
|
+
const providerEntityForName = (providerName) =>
|
|
410
|
+
providerName ? { name: String(providerName) } : undefined;
|
|
411
|
+
|
|
412
|
+
const legacyQuantizationValueFromFilename = (fileName) => {
|
|
413
|
+
const normalizedFileName = String(fileName || "").trim();
|
|
414
|
+
if (!normalizedFileName.toLowerCase().endsWith(".gguf")) {
|
|
415
|
+
return undefined;
|
|
416
|
+
}
|
|
417
|
+
const segments = basename(normalizedFileName, ".gguf").split(".");
|
|
418
|
+
return segments.length > 1 ? segments.at(-1) : undefined;
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
const quantizationValueFromFilename = (fileName) => {
|
|
422
|
+
const parsedFileName = parseGgufFilename(fileName);
|
|
423
|
+
if (parsedFileName?.encoding) {
|
|
424
|
+
return parsedFileName.encoding;
|
|
425
|
+
}
|
|
426
|
+
return legacyQuantizationValueFromFilename(fileName);
|
|
427
|
+
};
|
|
428
|
+
|
|
429
|
+
const createExternalReference = (type, url, comment) => {
|
|
430
|
+
const sanitizedUrl = sanitizeBomUrl(url);
|
|
431
|
+
if (!sanitizedUrl) {
|
|
432
|
+
return undefined;
|
|
433
|
+
}
|
|
434
|
+
const externalReference = {
|
|
435
|
+
type,
|
|
436
|
+
url: sanitizedUrl,
|
|
437
|
+
};
|
|
438
|
+
if (comment) {
|
|
439
|
+
externalReference.comment = comment;
|
|
440
|
+
}
|
|
441
|
+
return externalReference;
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
const uniqueExternalReferences = (references) => [
|
|
445
|
+
...new Map(
|
|
446
|
+
references.filter(Boolean).map((ref) => [`${ref.type}:${ref.url}`, ref]),
|
|
447
|
+
).values(),
|
|
448
|
+
];
|
|
449
|
+
|
|
450
|
+
const createGgufExternalReferences = (metadata = {}) =>
|
|
451
|
+
uniqueExternalReferences([
|
|
452
|
+
createExternalReference("website", metadata["general.url"]),
|
|
453
|
+
createExternalReference("vcs", metadata["general.repo_url"]),
|
|
454
|
+
createExternalReference(
|
|
455
|
+
"website",
|
|
456
|
+
metadata["general.source.url"],
|
|
457
|
+
"GGUF source metadata",
|
|
458
|
+
),
|
|
459
|
+
createExternalReference(
|
|
460
|
+
"vcs",
|
|
461
|
+
metadata["general.source.repo_url"],
|
|
462
|
+
"GGUF source repository",
|
|
463
|
+
),
|
|
464
|
+
createExternalReference("license", metadata["general.license.link"]),
|
|
465
|
+
createExternalReference(
|
|
466
|
+
"citation",
|
|
467
|
+
metadata["general.doi"]
|
|
468
|
+
? `https://doi.org/${metadata["general.doi"]}`
|
|
469
|
+
: undefined,
|
|
470
|
+
),
|
|
471
|
+
createExternalReference(
|
|
472
|
+
"citation",
|
|
473
|
+
metadata["general.source.doi"]
|
|
474
|
+
? `https://doi.org/${metadata["general.source.doi"]}`
|
|
475
|
+
: undefined,
|
|
476
|
+
"GGUF source DOI",
|
|
477
|
+
),
|
|
478
|
+
]);
|
|
479
|
+
|
|
480
|
+
const createGgufBaseModelReference = (metadata, index) => {
|
|
481
|
+
const baseKey = `general.base_model.${index}`;
|
|
482
|
+
const repoUrl = metadata[`${baseKey}.repo_url`];
|
|
483
|
+
const name = metadata[`${baseKey}.name`];
|
|
484
|
+
const organization = metadata[`${baseKey}.organization`];
|
|
485
|
+
const version = metadata[`${baseKey}.version`];
|
|
486
|
+
const referenceUrl = metadata[`${baseKey}.url`];
|
|
487
|
+
const huggingFaceReference = normalizeHuggingFaceReference(repoUrl);
|
|
488
|
+
const externalReferences = uniqueExternalReferences([
|
|
489
|
+
createExternalReference("website", referenceUrl),
|
|
490
|
+
createExternalReference("vcs", repoUrl),
|
|
491
|
+
createExternalReference(
|
|
492
|
+
"citation",
|
|
493
|
+
metadata[`${baseKey}.doi`]
|
|
494
|
+
? `https://doi.org/${metadata[`${baseKey}.doi`]}`
|
|
495
|
+
: undefined,
|
|
496
|
+
),
|
|
497
|
+
]);
|
|
498
|
+
if (huggingFaceReference?.assetType === "model") {
|
|
499
|
+
return {
|
|
500
|
+
"bom-ref": toHuggingFacePurl(huggingFaceReference.repoId),
|
|
501
|
+
type: "machine-learning-model",
|
|
502
|
+
group: huggingFaceReference.repoId.split("/")[0],
|
|
503
|
+
name: huggingFaceReference.repoId.split("/")[1],
|
|
504
|
+
purl: toHuggingFacePurl(huggingFaceReference.repoId),
|
|
505
|
+
version,
|
|
506
|
+
externalReferences,
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
if (!name && !repoUrl) {
|
|
510
|
+
return undefined;
|
|
511
|
+
}
|
|
512
|
+
const referenceName = name || repoUrl || `gguf-base-model-${index}`;
|
|
513
|
+
return {
|
|
514
|
+
"bom-ref": stableAiBomRef(
|
|
515
|
+
"model",
|
|
516
|
+
organization || "gguf-base-model",
|
|
517
|
+
referenceName,
|
|
518
|
+
),
|
|
519
|
+
type: "machine-learning-model",
|
|
520
|
+
group: organization,
|
|
521
|
+
name: referenceName,
|
|
522
|
+
version,
|
|
523
|
+
externalReferences,
|
|
524
|
+
};
|
|
525
|
+
};
|
|
526
|
+
|
|
527
|
+
const createGgufPedigree = (metadata = {}) => {
|
|
528
|
+
const baseModelIndexes = new Set();
|
|
529
|
+
const baseModelCount = Number(metadata["general.base_model.count"]);
|
|
530
|
+
if (Number.isInteger(baseModelCount) && baseModelCount > 0) {
|
|
531
|
+
for (let index = 0; index < baseModelCount; index++) {
|
|
532
|
+
baseModelIndexes.add(index);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
for (const key of Object.keys(metadata)) {
|
|
536
|
+
const match = /^general\.base_model\.(\d+)\./u.exec(key);
|
|
537
|
+
if (match) {
|
|
538
|
+
baseModelIndexes.add(Number.parseInt(match[1], 10));
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
const ancestors = Array.from(baseModelIndexes)
|
|
542
|
+
.sort((left, right) => left - right)
|
|
543
|
+
.map((index) => createGgufBaseModelReference(metadata, index))
|
|
544
|
+
.filter(Boolean);
|
|
545
|
+
if (!ancestors.length) {
|
|
546
|
+
return undefined;
|
|
547
|
+
}
|
|
548
|
+
return { ancestors };
|
|
549
|
+
};
|
|
550
|
+
|
|
551
|
+
const ggufStringArray = (value) =>
|
|
552
|
+
Array.isArray(value)
|
|
553
|
+
? value.map((entry) => String(entry || "").trim()).filter(Boolean)
|
|
554
|
+
: [];
|
|
555
|
+
|
|
556
|
+
const normalizeGgufAlignment = (value) => {
|
|
557
|
+
const numericValue =
|
|
558
|
+
typeof value === "string"
|
|
559
|
+
? (() => {
|
|
560
|
+
const normalizedValue = value.trim();
|
|
561
|
+
if (!/^\d+$/.test(normalizedValue)) {
|
|
562
|
+
return Number.NaN;
|
|
563
|
+
}
|
|
564
|
+
return Number(normalizedValue);
|
|
565
|
+
})()
|
|
566
|
+
: Number(value);
|
|
567
|
+
if (!Number.isInteger(numericValue)) {
|
|
568
|
+
return undefined;
|
|
569
|
+
}
|
|
570
|
+
if (numericValue < GGUF_MIN_ALIGNMENT || numericValue > GGUF_MAX_ALIGNMENT) {
|
|
571
|
+
return undefined;
|
|
572
|
+
}
|
|
573
|
+
return numericValue;
|
|
574
|
+
};
|
|
575
|
+
|
|
576
|
+
const ggufTokenizerSignals = (metadata = {}) => ({
|
|
577
|
+
addedTokenCount: ggufStringArray(metadata["tokenizer.ggml.added_tokens"])
|
|
578
|
+
.length,
|
|
579
|
+
bosTokenId: metadata["tokenizer.ggml.bos_token_id"],
|
|
580
|
+
chatTemplateDetected:
|
|
581
|
+
typeof metadata["tokenizer.chat_template"] === "string" &&
|
|
582
|
+
metadata["tokenizer.chat_template"].trim().length > 0,
|
|
583
|
+
chatTemplateLength:
|
|
584
|
+
typeof metadata["tokenizer.chat_template"] === "string"
|
|
585
|
+
? metadata["tokenizer.chat_template"].length
|
|
586
|
+
: undefined,
|
|
587
|
+
eosTokenId: metadata["tokenizer.ggml.eos_token_id"],
|
|
588
|
+
huggingFaceTokenizer:
|
|
589
|
+
typeof metadata["tokenizer.huggingface.json"] === "string" &&
|
|
590
|
+
metadata["tokenizer.huggingface.json"].trim().length > 0,
|
|
591
|
+
mergeCount: ggufStringArray(metadata["tokenizer.ggml.merges"]).length,
|
|
592
|
+
paddingTokenId: metadata["tokenizer.ggml.padding_token_id"],
|
|
593
|
+
scoreCount: Array.isArray(metadata["tokenizer.ggml.scores"])
|
|
594
|
+
? metadata["tokenizer.ggml.scores"].length
|
|
595
|
+
: undefined,
|
|
596
|
+
separatorTokenId: metadata["tokenizer.ggml.separator_token_id"],
|
|
597
|
+
tokenCount: ggufStringArray(metadata["tokenizer.ggml.tokens"]).length,
|
|
598
|
+
tokenizerModel: metadata["tokenizer.ggml.model"],
|
|
599
|
+
tokenTypeCount: Array.isArray(metadata["tokenizer.ggml.token_type"])
|
|
600
|
+
? metadata["tokenizer.ggml.token_type"].length
|
|
601
|
+
: undefined,
|
|
602
|
+
unknownTokenId: metadata["tokenizer.ggml.unknown_token_id"],
|
|
603
|
+
});
|
|
604
|
+
|
|
605
|
+
const inferGgufModelTask = (metadata, parsedFileName) => {
|
|
606
|
+
const tags = ggufStringArray(metadata["general.tags"]).map((tag) =>
|
|
607
|
+
tag.toLowerCase(),
|
|
608
|
+
);
|
|
609
|
+
const fineTune = String(metadata["general.finetune"] || "").toLowerCase();
|
|
610
|
+
if (
|
|
611
|
+
tags.includes("text-generation") ||
|
|
612
|
+
fineTune.includes("chat") ||
|
|
613
|
+
fineTune.includes("instruct") ||
|
|
614
|
+
fineTune.includes("coding") ||
|
|
615
|
+
fineTune.includes("code") ||
|
|
616
|
+
ggufTokenizerSignals(metadata).chatTemplateDetected
|
|
617
|
+
) {
|
|
618
|
+
return "text-generation";
|
|
619
|
+
}
|
|
620
|
+
if (
|
|
621
|
+
tags.includes("embedding") ||
|
|
622
|
+
tags.includes("embeddings") ||
|
|
623
|
+
String(parsedFileName?.baseName || "")
|
|
624
|
+
.toLowerCase()
|
|
625
|
+
.includes("embed")
|
|
626
|
+
) {
|
|
627
|
+
return "feature-extraction";
|
|
628
|
+
}
|
|
629
|
+
return undefined;
|
|
630
|
+
};
|
|
631
|
+
|
|
632
|
+
const createInlineDatasetReference = (datasetValue) => {
|
|
633
|
+
const normalizedDatasetValue = String(datasetValue || "").trim();
|
|
634
|
+
if (!normalizedDatasetValue) {
|
|
635
|
+
return undefined;
|
|
636
|
+
}
|
|
637
|
+
const sanitizedUrl = sanitizeBomUrl(normalizedDatasetValue);
|
|
638
|
+
if (sanitizedUrl) {
|
|
639
|
+
const huggingFaceReference = normalizeHuggingFaceReference(sanitizedUrl);
|
|
640
|
+
return {
|
|
641
|
+
type: "dataset",
|
|
642
|
+
name: huggingFaceReference?.repoId || sanitizedUrl,
|
|
643
|
+
contents: {
|
|
644
|
+
url: sanitizedUrl,
|
|
645
|
+
},
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
return {
|
|
649
|
+
type: "dataset",
|
|
650
|
+
name: normalizedDatasetValue,
|
|
651
|
+
};
|
|
652
|
+
};
|
|
653
|
+
|
|
654
|
+
const dedupeModelCardDatasets = (datasets) => [
|
|
655
|
+
...new Map(
|
|
656
|
+
datasets
|
|
657
|
+
.filter(Boolean)
|
|
658
|
+
.map((dataset) => [dataset.contents?.url || dataset.name, dataset]),
|
|
659
|
+
).values(),
|
|
660
|
+
];
|
|
661
|
+
|
|
662
|
+
const createGgufModelCard = (metadata, parsedFileName) => {
|
|
663
|
+
const architectureFamily = metadata["general.architecture"];
|
|
664
|
+
const modelArchitecture = metadata["general.basename"];
|
|
665
|
+
const datasets = dedupeModelCardDatasets(
|
|
666
|
+
ggufStringArray(metadata["general.datasets"]).map(
|
|
667
|
+
createInlineDatasetReference,
|
|
668
|
+
),
|
|
669
|
+
);
|
|
670
|
+
const task = inferGgufModelTask(metadata, parsedFileName);
|
|
671
|
+
const tokenizerSignals = ggufTokenizerSignals(metadata);
|
|
672
|
+
const modelCard = {
|
|
673
|
+
modelParameters: {},
|
|
674
|
+
};
|
|
675
|
+
if (architectureFamily) {
|
|
676
|
+
modelCard.modelParameters.architectureFamily = architectureFamily;
|
|
677
|
+
}
|
|
678
|
+
if (modelArchitecture) {
|
|
679
|
+
modelCard.modelParameters.modelArchitecture = modelArchitecture;
|
|
680
|
+
}
|
|
681
|
+
if (task) {
|
|
682
|
+
modelCard.modelParameters.task = task;
|
|
683
|
+
}
|
|
684
|
+
if (datasets.length) {
|
|
685
|
+
modelCard.modelParameters.datasets = datasets;
|
|
686
|
+
}
|
|
687
|
+
if (
|
|
688
|
+
tokenizerSignals.tokenizerModel ||
|
|
689
|
+
tokenizerSignals.chatTemplateDetected
|
|
690
|
+
) {
|
|
691
|
+
modelCard.modelParameters.inputs = [{ format: "text" }];
|
|
692
|
+
modelCard.modelParameters.outputs = [{ format: "text" }];
|
|
693
|
+
}
|
|
694
|
+
return Object.values(modelCard.modelParameters).some(Boolean)
|
|
695
|
+
? sanitizeStructuredValueForBom(modelCard)
|
|
696
|
+
: undefined;
|
|
697
|
+
};
|
|
698
|
+
|
|
699
|
+
const contextWindowFromGgufMetadata = (metadata = {}) => {
|
|
700
|
+
const architecture = String(metadata["general.architecture"] || "").trim();
|
|
701
|
+
if (
|
|
702
|
+
architecture &&
|
|
703
|
+
metadata[`${architecture}.context_length`] !== undefined
|
|
704
|
+
) {
|
|
705
|
+
return metadata[`${architecture}.context_length`];
|
|
706
|
+
}
|
|
707
|
+
if (metadata["general.context_length"] !== undefined) {
|
|
708
|
+
return metadata["general.context_length"];
|
|
709
|
+
}
|
|
710
|
+
for (const [key, value] of Object.entries(metadata)) {
|
|
711
|
+
if (key.endsWith(".context_length")) {
|
|
712
|
+
return value;
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
return undefined;
|
|
716
|
+
};
|
|
717
|
+
|
|
718
|
+
const ggufModelIdFromFilename = (parsedFileName, filePath) => {
|
|
719
|
+
const segments = [];
|
|
720
|
+
if (parsedFileName?.sidecar) {
|
|
721
|
+
segments.push(parsedFileName.sidecar);
|
|
722
|
+
}
|
|
723
|
+
if (parsedFileName?.baseName) {
|
|
724
|
+
segments.push(parsedFileName.baseName);
|
|
725
|
+
}
|
|
726
|
+
if (parsedFileName?.sizeLabel) {
|
|
727
|
+
segments.push(parsedFileName.sizeLabel);
|
|
728
|
+
}
|
|
729
|
+
if (parsedFileName?.fineTune) {
|
|
730
|
+
segments.push(parsedFileName.fineTune);
|
|
731
|
+
}
|
|
732
|
+
if (parsedFileName?.type) {
|
|
733
|
+
segments.push(parsedFileName.type);
|
|
734
|
+
}
|
|
735
|
+
if (segments.length) {
|
|
736
|
+
return segments.join("-");
|
|
737
|
+
}
|
|
738
|
+
return basename(filePath, extname(filePath));
|
|
739
|
+
};
|
|
740
|
+
|
|
741
|
+
const applyGgufProperties = (
|
|
742
|
+
subject,
|
|
743
|
+
metadata,
|
|
744
|
+
parsedFileName,
|
|
745
|
+
includeArtifactDetails,
|
|
746
|
+
) => {
|
|
747
|
+
const tokenizerSignals = ggufTokenizerSignals(metadata);
|
|
748
|
+
addUniqueProperty(
|
|
749
|
+
subject.properties,
|
|
750
|
+
"cdx:gguf:basename",
|
|
751
|
+
metadata["general.basename"] || parsedFileName?.baseName,
|
|
752
|
+
);
|
|
753
|
+
addUniqueProperty(
|
|
754
|
+
subject.properties,
|
|
755
|
+
"cdx:gguf:sizeLabel",
|
|
756
|
+
metadata["general.size_label"] || parsedFileName?.sizeLabel,
|
|
757
|
+
);
|
|
758
|
+
addUniqueProperty(
|
|
759
|
+
subject.properties,
|
|
760
|
+
"cdx:gguf:finetune",
|
|
761
|
+
metadata["general.finetune"] || parsedFileName?.fineTune,
|
|
762
|
+
);
|
|
763
|
+
addUniqueProperty(
|
|
764
|
+
subject.properties,
|
|
765
|
+
"cdx:gguf:quantizationVersion",
|
|
766
|
+
metadata["general.quantization_version"],
|
|
767
|
+
);
|
|
768
|
+
addUniqueProperty(
|
|
769
|
+
subject.properties,
|
|
770
|
+
"cdx:gguf:quantizedBy",
|
|
771
|
+
metadata["general.quantized_by"],
|
|
772
|
+
);
|
|
773
|
+
addUniqueProperty(
|
|
774
|
+
subject.properties,
|
|
775
|
+
"cdx:gguf:sidecar",
|
|
776
|
+
parsedFileName?.sidecar,
|
|
777
|
+
);
|
|
778
|
+
addUniqueProperty(subject.properties, "cdx:gguf:type", parsedFileName?.type);
|
|
779
|
+
addUniqueProperty(
|
|
780
|
+
subject.properties,
|
|
781
|
+
"cdx:gguf:tokenizerModel",
|
|
782
|
+
tokenizerSignals.tokenizerModel,
|
|
783
|
+
);
|
|
784
|
+
addUniqueProperty(
|
|
785
|
+
subject.properties,
|
|
786
|
+
"cdx:gguf:tokenizerTokenCount",
|
|
787
|
+
tokenizerSignals.tokenCount,
|
|
788
|
+
);
|
|
789
|
+
addUniqueProperty(
|
|
790
|
+
subject.properties,
|
|
791
|
+
"cdx:gguf:tokenizerScoreCount",
|
|
792
|
+
tokenizerSignals.scoreCount,
|
|
793
|
+
);
|
|
794
|
+
addUniqueProperty(
|
|
795
|
+
subject.properties,
|
|
796
|
+
"cdx:gguf:tokenizerTokenTypeCount",
|
|
797
|
+
tokenizerSignals.tokenTypeCount,
|
|
798
|
+
);
|
|
799
|
+
addUniqueProperty(
|
|
800
|
+
subject.properties,
|
|
801
|
+
"cdx:gguf:tokenizerMergeCount",
|
|
802
|
+
tokenizerSignals.mergeCount,
|
|
803
|
+
);
|
|
804
|
+
addUniqueProperty(
|
|
805
|
+
subject.properties,
|
|
806
|
+
"cdx:gguf:tokenizerAddedTokenCount",
|
|
807
|
+
tokenizerSignals.addedTokenCount,
|
|
808
|
+
);
|
|
809
|
+
addUniqueProperty(
|
|
810
|
+
subject.properties,
|
|
811
|
+
"cdx:gguf:huggingFaceTokenizer",
|
|
812
|
+
tokenizerSignals.huggingFaceTokenizer ? "true" : undefined,
|
|
813
|
+
);
|
|
814
|
+
addUniqueProperty(
|
|
815
|
+
subject.properties,
|
|
816
|
+
"cdx:gguf:chatTemplateDetected",
|
|
817
|
+
tokenizerSignals.chatTemplateDetected ? "true" : undefined,
|
|
818
|
+
);
|
|
819
|
+
addUniqueProperty(
|
|
820
|
+
subject.properties,
|
|
821
|
+
"cdx:gguf:chatTemplateLength",
|
|
822
|
+
tokenizerSignals.chatTemplateLength,
|
|
823
|
+
);
|
|
824
|
+
addUniqueProperty(
|
|
825
|
+
subject.properties,
|
|
826
|
+
"cdx:gguf:bosTokenId",
|
|
827
|
+
tokenizerSignals.bosTokenId,
|
|
828
|
+
);
|
|
829
|
+
addUniqueProperty(
|
|
830
|
+
subject.properties,
|
|
831
|
+
"cdx:gguf:eosTokenId",
|
|
832
|
+
tokenizerSignals.eosTokenId,
|
|
833
|
+
);
|
|
834
|
+
addUniqueProperty(
|
|
835
|
+
subject.properties,
|
|
836
|
+
"cdx:gguf:unknownTokenId",
|
|
837
|
+
tokenizerSignals.unknownTokenId,
|
|
838
|
+
);
|
|
839
|
+
addUniqueProperty(
|
|
840
|
+
subject.properties,
|
|
841
|
+
"cdx:gguf:separatorTokenId",
|
|
842
|
+
tokenizerSignals.separatorTokenId,
|
|
843
|
+
);
|
|
844
|
+
addUniqueProperty(
|
|
845
|
+
subject.properties,
|
|
846
|
+
"cdx:gguf:paddingTokenId",
|
|
847
|
+
tokenizerSignals.paddingTokenId,
|
|
848
|
+
);
|
|
849
|
+
for (const language of ggufStringArray(metadata["general.languages"])) {
|
|
850
|
+
addUniqueProperty(subject.properties, "cdx:gguf:language", language);
|
|
851
|
+
}
|
|
852
|
+
addUniqueProperty(
|
|
853
|
+
subject.properties,
|
|
854
|
+
"cdx:gguf:datasetCount",
|
|
855
|
+
ggufStringArray(metadata["general.datasets"]).length || undefined,
|
|
856
|
+
);
|
|
857
|
+
if (!includeArtifactDetails) {
|
|
858
|
+
return;
|
|
859
|
+
}
|
|
860
|
+
addUniqueProperty(
|
|
861
|
+
subject.properties,
|
|
862
|
+
"cdx:gguf:formatVersion",
|
|
863
|
+
metadata["gguf.version"],
|
|
864
|
+
);
|
|
865
|
+
addUniqueProperty(
|
|
866
|
+
subject.properties,
|
|
867
|
+
"cdx:gguf:tensorCount",
|
|
868
|
+
metadata["gguf.tensorCount"],
|
|
869
|
+
);
|
|
870
|
+
addUniqueProperty(
|
|
871
|
+
subject.properties,
|
|
872
|
+
"cdx:gguf:metadataCount",
|
|
873
|
+
metadata["gguf.metadataCount"],
|
|
874
|
+
);
|
|
875
|
+
addUniqueProperty(
|
|
876
|
+
subject.properties,
|
|
877
|
+
"cdx:gguf:alignment",
|
|
878
|
+
normalizeGgufAlignment(metadata["general.alignment"]),
|
|
879
|
+
);
|
|
880
|
+
addUniqueProperty(
|
|
881
|
+
subject.properties,
|
|
882
|
+
"cdx:gguf:shard",
|
|
883
|
+
parsedFileName?.shard,
|
|
884
|
+
);
|
|
885
|
+
addUniqueProperty(
|
|
886
|
+
subject.properties,
|
|
887
|
+
"cdx:gguf:shardIndex",
|
|
888
|
+
parsedFileName?.shardIndex,
|
|
889
|
+
);
|
|
890
|
+
addUniqueProperty(
|
|
891
|
+
subject.properties,
|
|
892
|
+
"cdx:gguf:shardCount",
|
|
893
|
+
parsedFileName?.shardCount,
|
|
894
|
+
);
|
|
895
|
+
};
|
|
896
|
+
|
|
897
|
+
const extractHuggingFaceArtifactDetails = (sourceUrl) => {
|
|
898
|
+
if (!sourceUrl) {
|
|
899
|
+
return {};
|
|
900
|
+
}
|
|
901
|
+
try {
|
|
902
|
+
const parsed = new URL(sourceUrl);
|
|
903
|
+
const fileName = basename(parsed.pathname);
|
|
904
|
+
const artifactFormat = fileName.toLowerCase().endsWith(".gguf")
|
|
905
|
+
? "gguf"
|
|
906
|
+
: undefined;
|
|
907
|
+
const parsedGgufFileName = parseGgufFilename(fileName);
|
|
908
|
+
return {
|
|
909
|
+
artifactFormat,
|
|
910
|
+
quantization:
|
|
911
|
+
parsedGgufFileName?.encoding || quantizationValueFromFilename(fileName),
|
|
912
|
+
sourceUrl,
|
|
913
|
+
};
|
|
914
|
+
} catch {
|
|
915
|
+
return {};
|
|
916
|
+
}
|
|
917
|
+
};
|
|
918
|
+
|
|
919
|
+
const dependencyListFromMap = (dependencyMap) =>
|
|
920
|
+
Array.from(dependencyMap.entries()).map(([ref, dependsOn]) => ({
|
|
921
|
+
ref,
|
|
922
|
+
dependsOn: Array.from(dependsOn).sort(),
|
|
923
|
+
}));
|
|
924
|
+
|
|
925
|
+
const buildAiInventoryResult = (
|
|
926
|
+
componentsByKey,
|
|
927
|
+
servicesByKey,
|
|
928
|
+
dependencyMap,
|
|
929
|
+
) => {
|
|
930
|
+
const components = Array.from(componentsByKey.values()).map((component) => {
|
|
931
|
+
applyOccurrenceEvidence(component, component?.evidence?.occurrences || []);
|
|
932
|
+
return component;
|
|
933
|
+
});
|
|
934
|
+
const services = Array.from(servicesByKey.values()).map((service) => {
|
|
935
|
+
syncServiceProperties(service);
|
|
936
|
+
return serializeAiService(service);
|
|
937
|
+
});
|
|
938
|
+
const dependencies = dependencyListFromMap(dependencyMap);
|
|
939
|
+
for (const service of services) {
|
|
940
|
+
const source = servicesByKey.get(`${service.group}:${service.name}`);
|
|
941
|
+
const dependsOn = new Set([
|
|
942
|
+
...Array.from(source?.modelRefs || []),
|
|
943
|
+
...Array.from(source?.fileRefs || []),
|
|
944
|
+
]);
|
|
945
|
+
if (dependsOn.size) {
|
|
946
|
+
dependencies.push({
|
|
947
|
+
ref: service["bom-ref"],
|
|
948
|
+
dependsOn: Array.from(dependsOn).sort(),
|
|
949
|
+
});
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
return { components, dependencies, services };
|
|
953
|
+
};
|
|
954
|
+
|
|
955
|
+
const classifyImport = (importName) =>
|
|
956
|
+
AI_PACKAGE_REGISTRY.find((entry) => entry.pattern.test(importName));
|
|
957
|
+
|
|
958
|
+
const getSourceFiles = (discoveryPath, patterns, options) => {
|
|
959
|
+
const files = new Set();
|
|
960
|
+
const directFileMatches = getDirectDiscoveryFileMatches(
|
|
961
|
+
discoveryPath,
|
|
962
|
+
patterns,
|
|
963
|
+
);
|
|
964
|
+
for (const filePath of directFileMatches) {
|
|
965
|
+
const normalizedFilePath = String(filePath || "");
|
|
966
|
+
if (
|
|
967
|
+
normalizedFilePath.includes("/node_modules/") ||
|
|
968
|
+
normalizedFilePath.includes("\\node_modules\\") ||
|
|
969
|
+
IGNORE_SOURCE_FILE_PATTERN.test(normalizedFilePath)
|
|
970
|
+
) {
|
|
971
|
+
continue;
|
|
972
|
+
}
|
|
973
|
+
files.add(filePath);
|
|
974
|
+
}
|
|
975
|
+
if (isDirectDiscoveryFile(discoveryPath)) {
|
|
976
|
+
return Array.from(files).sort();
|
|
977
|
+
}
|
|
978
|
+
for (const pattern of patterns) {
|
|
979
|
+
for (const filePath of getAllFiles(discoveryPath, pattern, options) || []) {
|
|
980
|
+
const normalizedFilePath = String(filePath || "");
|
|
981
|
+
if (
|
|
982
|
+
normalizedFilePath.includes("/node_modules/") ||
|
|
983
|
+
normalizedFilePath.includes("\\node_modules\\") ||
|
|
984
|
+
IGNORE_SOURCE_FILE_PATTERN.test(normalizedFilePath)
|
|
985
|
+
) {
|
|
986
|
+
continue;
|
|
987
|
+
}
|
|
988
|
+
files.add(filePath);
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
return Array.from(files).sort();
|
|
992
|
+
};
|
|
993
|
+
|
|
994
|
+
const getMatchingFiles = (discoveryPath, patterns, options) => {
|
|
995
|
+
const files = new Set();
|
|
996
|
+
for (const filePath of getDirectDiscoveryFileMatches(
|
|
997
|
+
discoveryPath,
|
|
998
|
+
patterns,
|
|
999
|
+
)) {
|
|
1000
|
+
files.add(filePath);
|
|
1001
|
+
}
|
|
1002
|
+
if (isDirectDiscoveryFile(discoveryPath)) {
|
|
1003
|
+
return Array.from(files).sort();
|
|
1004
|
+
}
|
|
1005
|
+
for (const pattern of patterns) {
|
|
1006
|
+
for (const filePath of getAllFiles(discoveryPath, pattern, options) || []) {
|
|
1007
|
+
files.add(filePath);
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
return Array.from(files).sort();
|
|
1011
|
+
};
|
|
1012
|
+
|
|
1013
|
+
const isDirectDiscoveryFile = (discoveryPath) => {
|
|
1014
|
+
try {
|
|
1015
|
+
return statSync(discoveryPath).isFile();
|
|
1016
|
+
} catch {
|
|
1017
|
+
return false;
|
|
1018
|
+
}
|
|
1019
|
+
};
|
|
1020
|
+
|
|
1021
|
+
const getDirectDiscoveryFileMatches = (discoveryPath, patterns) => {
|
|
1022
|
+
if (!isDirectDiscoveryFile(discoveryPath)) {
|
|
1023
|
+
return [];
|
|
1024
|
+
}
|
|
1025
|
+
const normalizedPath = String(discoveryPath || "");
|
|
1026
|
+
const filename = basename(normalizedPath);
|
|
1027
|
+
const extension = extname(normalizedPath).toLowerCase();
|
|
1028
|
+
if (
|
|
1029
|
+
patterns.includes("Modelfile") &&
|
|
1030
|
+
(filename === "Modelfile" || filename.startsWith("Modelfile."))
|
|
1031
|
+
) {
|
|
1032
|
+
return [normalizedPath];
|
|
1033
|
+
}
|
|
1034
|
+
if (patterns.includes("**/*.gguf") && extension === ".gguf") {
|
|
1035
|
+
return [normalizedPath];
|
|
1036
|
+
}
|
|
1037
|
+
if (
|
|
1038
|
+
patterns.some((pattern) =>
|
|
1039
|
+
pattern.includes("*.{js,jsx,cjs,mjs,ts,tsx,mts,cts,vue,svelte}"),
|
|
1040
|
+
) &&
|
|
1041
|
+
[
|
|
1042
|
+
".js",
|
|
1043
|
+
".jsx",
|
|
1044
|
+
".cjs",
|
|
1045
|
+
".mjs",
|
|
1046
|
+
".ts",
|
|
1047
|
+
".tsx",
|
|
1048
|
+
".mts",
|
|
1049
|
+
".cts",
|
|
1050
|
+
".vue",
|
|
1051
|
+
".svelte",
|
|
1052
|
+
].includes(extension)
|
|
1053
|
+
) {
|
|
1054
|
+
return [normalizedPath];
|
|
1055
|
+
}
|
|
1056
|
+
if (
|
|
1057
|
+
patterns.some((pattern) => pattern.includes("*.{py,pyw}")) &&
|
|
1058
|
+
[".py", ".pyw"].includes(extension)
|
|
1059
|
+
) {
|
|
1060
|
+
return [normalizedPath];
|
|
1061
|
+
}
|
|
1062
|
+
if (patterns.includes("**/*.ipynb") && extension === ".ipynb") {
|
|
1063
|
+
return [normalizedPath];
|
|
1064
|
+
}
|
|
1065
|
+
return [];
|
|
1066
|
+
};
|
|
1067
|
+
|
|
1068
|
+
const defaultServiceNameForProvider = (provider) =>
|
|
1069
|
+
AI_PACKAGE_REGISTRY.find(
|
|
1070
|
+
(entry) => entry.provider === provider && entry.serviceName,
|
|
1071
|
+
)?.serviceName || `${provider || "ai"}-service`;
|
|
1072
|
+
|
|
1073
|
+
const fileBomRef = (discoveryPath, filePath) =>
|
|
1074
|
+
`urn:file:ai:${(relative(discoveryPath, filePath) || basename(filePath)).replaceAll(/[^a-zA-Z0-9._:/-]+/gu, "-")}`;
|
|
1075
|
+
|
|
1076
|
+
const createAiFileComponent = (
|
|
1077
|
+
componentsByKey,
|
|
1078
|
+
discoveryPath,
|
|
1079
|
+
filePath,
|
|
1080
|
+
kind,
|
|
1081
|
+
tags = [],
|
|
1082
|
+
) => {
|
|
1083
|
+
const key = `file:${relative(discoveryPath, filePath) || basename(filePath)}`;
|
|
1084
|
+
if (!componentsByKey.has(key)) {
|
|
1085
|
+
const location = relativeOccurrenceLocation(discoveryPath, filePath);
|
|
1086
|
+
componentsByKey.set(key, {
|
|
1087
|
+
"bom-ref": fileBomRef(discoveryPath, filePath),
|
|
1088
|
+
type: "file",
|
|
1089
|
+
name: basename(filePath),
|
|
1090
|
+
evidence: { occurrences: [{ location }] },
|
|
1091
|
+
properties: [
|
|
1092
|
+
{ name: "cdx:file:kind", value: kind },
|
|
1093
|
+
{ name: "cdx:ai:kind", value: kind },
|
|
1094
|
+
{ name: "cdx:ai:source", value: "source-code-analysis" },
|
|
1095
|
+
],
|
|
1096
|
+
tags: ["ai", kind, ...tags],
|
|
1097
|
+
});
|
|
1098
|
+
}
|
|
1099
|
+
return componentsByKey.get(key);
|
|
1100
|
+
};
|
|
1101
|
+
|
|
1102
|
+
const normalizeComponentIdentity = ({
|
|
1103
|
+
assetType,
|
|
1104
|
+
modelId,
|
|
1105
|
+
provider,
|
|
1106
|
+
version,
|
|
1107
|
+
}) => {
|
|
1108
|
+
const normalizedAssetType = ["dataset", "space"].includes(assetType)
|
|
1109
|
+
? assetType
|
|
1110
|
+
: "model";
|
|
1111
|
+
const normalizedModelId = String(modelId || "").trim();
|
|
1112
|
+
const normalizedProvider = String(provider || "ai").trim();
|
|
1113
|
+
const typedModelId =
|
|
1114
|
+
normalizedAssetType === "dataset"
|
|
1115
|
+
? `datasets/${normalizedModelId.replace(/^datasets\//u, "")}`
|
|
1116
|
+
: normalizedAssetType === "space"
|
|
1117
|
+
? `spaces/${normalizedModelId.replace(/^spaces\//u, "")}`
|
|
1118
|
+
: normalizedModelId;
|
|
1119
|
+
const repoId = normalizeHuggingFaceReference(typedModelId);
|
|
1120
|
+
if (
|
|
1121
|
+
repoId?.assetType === normalizedAssetType &&
|
|
1122
|
+
repoId?.repoId?.includes("/")
|
|
1123
|
+
) {
|
|
1124
|
+
const [group, name] = repoId.repoId.split("/");
|
|
1125
|
+
const purl = toHuggingFacePurl(
|
|
1126
|
+
repoId.repoId,
|
|
1127
|
+
repoId.version || version,
|
|
1128
|
+
repositoryUrlForHuggingFaceAssetType(normalizedAssetType),
|
|
1129
|
+
);
|
|
1130
|
+
return {
|
|
1131
|
+
bomRef: purl,
|
|
1132
|
+
group,
|
|
1133
|
+
name,
|
|
1134
|
+
purl,
|
|
1135
|
+
};
|
|
1136
|
+
}
|
|
1137
|
+
return {
|
|
1138
|
+
bomRef: stableAiBomRef(
|
|
1139
|
+
normalizedAssetType,
|
|
1140
|
+
normalizedProvider,
|
|
1141
|
+
normalizedModelId,
|
|
1142
|
+
),
|
|
1143
|
+
group: normalizedProvider,
|
|
1144
|
+
name: normalizedModelId,
|
|
1145
|
+
};
|
|
1146
|
+
};
|
|
1147
|
+
|
|
1148
|
+
const ensureModelComponent = (componentsByKey, key, seed) => {
|
|
1149
|
+
if (!componentsByKey.has(key)) {
|
|
1150
|
+
const identity = normalizeComponentIdentity(seed);
|
|
1151
|
+
const type =
|
|
1152
|
+
seed.assetType === "dataset"
|
|
1153
|
+
? "data"
|
|
1154
|
+
: seed.assetType === "space"
|
|
1155
|
+
? "application"
|
|
1156
|
+
: "machine-learning-model";
|
|
1157
|
+
componentsByKey.set(key, {
|
|
1158
|
+
"bom-ref": identity.bomRef,
|
|
1159
|
+
type,
|
|
1160
|
+
group: identity.group,
|
|
1161
|
+
name: identity.name,
|
|
1162
|
+
purl: identity.purl,
|
|
1163
|
+
description: seed.description,
|
|
1164
|
+
version: seed.version,
|
|
1165
|
+
licenses: seed.licenses,
|
|
1166
|
+
externalReferences: seed.externalReferences || [],
|
|
1167
|
+
evidence: { occurrences: [] },
|
|
1168
|
+
modelCard: seed.modelCard
|
|
1169
|
+
? sanitizeStructuredValueForBom(seed.modelCard)
|
|
1170
|
+
: undefined,
|
|
1171
|
+
pedigree: seed.pedigree,
|
|
1172
|
+
properties: [],
|
|
1173
|
+
tags: ["ai"],
|
|
1174
|
+
});
|
|
1175
|
+
}
|
|
1176
|
+
return componentsByKey.get(key);
|
|
1177
|
+
};
|
|
1178
|
+
|
|
1179
|
+
const ensureService = (servicesByKey, provider, serviceName) => {
|
|
1180
|
+
const normalizedProvider = provider || "ai";
|
|
1181
|
+
const resolvedServiceName =
|
|
1182
|
+
serviceName || defaultServiceNameForProvider(normalizedProvider);
|
|
1183
|
+
const key = `${normalizedProvider}:${resolvedServiceName}`;
|
|
1184
|
+
if (!servicesByKey.has(key)) {
|
|
1185
|
+
servicesByKey.set(key, {
|
|
1186
|
+
"bom-ref": `urn:service:ai:${normalizedProvider}:${String(
|
|
1187
|
+
serviceName || `${normalizedProvider}-service`,
|
|
1188
|
+
).replaceAll(/[^a-zA-Z0-9._:-]+/gu, "-")}`,
|
|
1189
|
+
group: normalizedProvider,
|
|
1190
|
+
name: resolvedServiceName,
|
|
1191
|
+
provider: providerEntityForName(normalizedProvider),
|
|
1192
|
+
version: "observed",
|
|
1193
|
+
endpoints: new Set(),
|
|
1194
|
+
modelRefs: new Set(),
|
|
1195
|
+
modelIds: new Set(),
|
|
1196
|
+
modelFamilies: new Set(),
|
|
1197
|
+
frameworks: new Set(),
|
|
1198
|
+
runtimes: new Set(),
|
|
1199
|
+
sdkImports: new Set(),
|
|
1200
|
+
fileRefs: new Set(),
|
|
1201
|
+
occurrences: [],
|
|
1202
|
+
properties: [],
|
|
1203
|
+
tags: new Set(["ai"]),
|
|
1204
|
+
});
|
|
1205
|
+
}
|
|
1206
|
+
return servicesByKey.get(key);
|
|
1207
|
+
};
|
|
1208
|
+
|
|
1209
|
+
const syncComponentProperties = (component, data = {}) => {
|
|
1210
|
+
if (data.provider) {
|
|
1211
|
+
addUniqueProperty(component.properties, "cdx:ai:provider", data.provider);
|
|
1212
|
+
}
|
|
1213
|
+
if (data.kind) {
|
|
1214
|
+
addUniqueProperty(component.properties, "cdx:ai:kind", data.kind);
|
|
1215
|
+
}
|
|
1216
|
+
if (data.modelFamily) {
|
|
1217
|
+
addUniqueProperty(
|
|
1218
|
+
component.properties,
|
|
1219
|
+
"cdx:ai:modelFamily",
|
|
1220
|
+
data.modelFamily,
|
|
1221
|
+
);
|
|
1222
|
+
}
|
|
1223
|
+
if (data.artifactFormat) {
|
|
1224
|
+
addUniqueProperty(
|
|
1225
|
+
component.properties,
|
|
1226
|
+
"cdx:ai:artifactFormat",
|
|
1227
|
+
data.artifactFormat,
|
|
1228
|
+
);
|
|
1229
|
+
}
|
|
1230
|
+
if (data.runtime) {
|
|
1231
|
+
addUniqueProperty(component.properties, "cdx:ai:runtime", data.runtime);
|
|
1232
|
+
}
|
|
1233
|
+
if (data.quantization) {
|
|
1234
|
+
addUniqueProperty(
|
|
1235
|
+
component.properties,
|
|
1236
|
+
"cdx:ai:quantization",
|
|
1237
|
+
data.quantization,
|
|
1238
|
+
);
|
|
1239
|
+
}
|
|
1240
|
+
for (const variant of data.variants || []) {
|
|
1241
|
+
addUniqueProperty(component.properties, "cdx:ai:variant", variant);
|
|
1242
|
+
}
|
|
1243
|
+
if (data.parameterCount !== undefined) {
|
|
1244
|
+
addUniqueProperty(
|
|
1245
|
+
component.properties,
|
|
1246
|
+
"cdx:ai:parameterCount",
|
|
1247
|
+
data.parameterCount,
|
|
1248
|
+
);
|
|
1249
|
+
}
|
|
1250
|
+
if (data.contextWindow !== undefined) {
|
|
1251
|
+
addUniqueProperty(
|
|
1252
|
+
component.properties,
|
|
1253
|
+
"cdx:ai:contextWindow",
|
|
1254
|
+
data.contextWindow,
|
|
1255
|
+
);
|
|
1256
|
+
}
|
|
1257
|
+
if (data.modality) {
|
|
1258
|
+
addUniqueProperty(component.properties, "cdx:ai:modality", data.modality);
|
|
1259
|
+
}
|
|
1260
|
+
if (data.source) {
|
|
1261
|
+
addUniqueProperty(component.properties, "cdx:ai:source", data.source);
|
|
1262
|
+
}
|
|
1263
|
+
if (data.confidence) {
|
|
1264
|
+
addUniqueProperty(
|
|
1265
|
+
component.properties,
|
|
1266
|
+
"cdx:ai:confidence",
|
|
1267
|
+
data.confidence,
|
|
1268
|
+
);
|
|
1269
|
+
}
|
|
1270
|
+
if (data.reviewNeeded) {
|
|
1271
|
+
addUniqueProperty(component.properties, "cdx:ai:reviewNeeded", "true");
|
|
1272
|
+
}
|
|
1273
|
+
};
|
|
1274
|
+
|
|
1275
|
+
const aiModelVariantsFromSeed = (seed = {}) =>
|
|
1276
|
+
detectAiModelVariants({
|
|
1277
|
+
description: seed.description,
|
|
1278
|
+
metadata: [
|
|
1279
|
+
seed.artifactFormat,
|
|
1280
|
+
seed.modelFamily,
|
|
1281
|
+
seed.runtime,
|
|
1282
|
+
seed.source,
|
|
1283
|
+
seed.modelCard?.modelParameters?.task,
|
|
1284
|
+
...(seed.modelCard?.modelParameters?.datasets || []).map(
|
|
1285
|
+
(dataset) => dataset?.name || dataset?.ref,
|
|
1286
|
+
),
|
|
1287
|
+
],
|
|
1288
|
+
modelName: [seed.modelId, seed.name],
|
|
1289
|
+
notes: [seed.pedigree?.notes],
|
|
1290
|
+
quantization: seed.quantization,
|
|
1291
|
+
relation:
|
|
1292
|
+
String(seed.pedigree?.notes || "")
|
|
1293
|
+
.match(/Hugging Face relation:\s*([^;]+)/u)?.[1]
|
|
1294
|
+
?.trim() || seed.relation,
|
|
1295
|
+
tags: seed.tags,
|
|
1296
|
+
});
|
|
1297
|
+
|
|
1298
|
+
const syncServiceProperties = (service) => {
|
|
1299
|
+
service.properties = [];
|
|
1300
|
+
addUniqueProperty(service.properties, "cdx:ai:kind", "inference-service");
|
|
1301
|
+
addUniqueProperty(
|
|
1302
|
+
service.properties,
|
|
1303
|
+
"cdx:ai:source",
|
|
1304
|
+
"source-code-analysis",
|
|
1305
|
+
);
|
|
1306
|
+
const sortedFamilies = Array.from(service.modelFamilies).sort();
|
|
1307
|
+
const sortedModelIds = Array.from(service.modelIds).sort();
|
|
1308
|
+
const endpoints = Array.from(service.endpoints);
|
|
1309
|
+
const remoteEndpoints = [];
|
|
1310
|
+
const localEndpoints = [];
|
|
1311
|
+
for (const endpoint of endpoints) {
|
|
1312
|
+
try {
|
|
1313
|
+
const parsed = new URL(endpoint);
|
|
1314
|
+
if (isLocalAiHostname(parsed.hostname)) {
|
|
1315
|
+
localEndpoints.push(endpoint);
|
|
1316
|
+
} else {
|
|
1317
|
+
remoteEndpoints.push(endpoint);
|
|
1318
|
+
}
|
|
1319
|
+
} catch {
|
|
1320
|
+
// Ignore malformed endpoints captured from source strings.
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
for (const modelId of sortedModelIds) {
|
|
1324
|
+
addUniqueProperty(service.properties, "cdx:ai:modelId", modelId);
|
|
1325
|
+
}
|
|
1326
|
+
for (const modelFamily of sortedFamilies) {
|
|
1327
|
+
addUniqueProperty(service.properties, "cdx:ai:modelFamily", modelFamily);
|
|
1328
|
+
}
|
|
1329
|
+
addUniqueProperty(
|
|
1330
|
+
service.properties,
|
|
1331
|
+
"cdx:ai:modelCount",
|
|
1332
|
+
String(sortedModelIds.length),
|
|
1333
|
+
);
|
|
1334
|
+
addUniqueProperty(
|
|
1335
|
+
service.properties,
|
|
1336
|
+
"cdx:ai:modelSelection",
|
|
1337
|
+
sortedModelIds.length ? "explicit" : "implicit",
|
|
1338
|
+
);
|
|
1339
|
+
addUniqueProperty(
|
|
1340
|
+
service.properties,
|
|
1341
|
+
"cdx:ai:deployment",
|
|
1342
|
+
remoteEndpoints.length
|
|
1343
|
+
? "remote"
|
|
1344
|
+
: localEndpoints.length
|
|
1345
|
+
? "local"
|
|
1346
|
+
: "implicit",
|
|
1347
|
+
);
|
|
1348
|
+
addUniqueProperty(
|
|
1349
|
+
service.properties,
|
|
1350
|
+
"cdx:ai:transportSecurity",
|
|
1351
|
+
remoteEndpoints.some((endpoint) => endpoint.startsWith("http://"))
|
|
1352
|
+
? "insecure-http"
|
|
1353
|
+
: remoteEndpoints.length
|
|
1354
|
+
? "https"
|
|
1355
|
+
: localEndpoints.length
|
|
1356
|
+
? "local-only"
|
|
1357
|
+
: "unknown",
|
|
1358
|
+
);
|
|
1359
|
+
if (service.runtimes.size) {
|
|
1360
|
+
addUniqueProperty(
|
|
1361
|
+
service.properties,
|
|
1362
|
+
"cdx:ai:runtime",
|
|
1363
|
+
Array.from(service.runtimes).sort().join(","),
|
|
1364
|
+
);
|
|
1365
|
+
}
|
|
1366
|
+
addUniqueProperty(
|
|
1367
|
+
service.properties,
|
|
1368
|
+
"cdx:ai:confidence",
|
|
1369
|
+
sortedModelIds.length || service.endpoints.size ? "high" : "medium",
|
|
1370
|
+
);
|
|
1371
|
+
if (
|
|
1372
|
+
service.group === "ollama" ||
|
|
1373
|
+
Array.from(service.endpoints).some((endpoint) =>
|
|
1374
|
+
endpoint.includes("localhost"),
|
|
1375
|
+
)
|
|
1376
|
+
) {
|
|
1377
|
+
addUniqueProperty(service.properties, "cdx:ai:reviewNeeded", "true");
|
|
1378
|
+
}
|
|
1379
|
+
};
|
|
1380
|
+
|
|
1381
|
+
const appendImportSignals = (
|
|
1382
|
+
importName,
|
|
1383
|
+
occurrence,
|
|
1384
|
+
fileSignals,
|
|
1385
|
+
servicesByKey,
|
|
1386
|
+
) => {
|
|
1387
|
+
const classification = classifyImport(importName);
|
|
1388
|
+
if (!classification) {
|
|
1389
|
+
return;
|
|
1390
|
+
}
|
|
1391
|
+
if (classification.framework) {
|
|
1392
|
+
fileSignals.frameworks.add(classification.framework);
|
|
1393
|
+
}
|
|
1394
|
+
if (classification.provider) {
|
|
1395
|
+
fileSignals.providers.add(classification.provider);
|
|
1396
|
+
const service = ensureService(
|
|
1397
|
+
servicesByKey,
|
|
1398
|
+
classification.provider,
|
|
1399
|
+
classification.serviceName,
|
|
1400
|
+
);
|
|
1401
|
+
service.sdkImports.add(importName);
|
|
1402
|
+
service.tags.add(classification.provider);
|
|
1403
|
+
appendOccurrence(
|
|
1404
|
+
service,
|
|
1405
|
+
occurrence.fileName
|
|
1406
|
+
? `${occurrence.fileName}${occurrence.lineNumber ? `#L${occurrence.lineNumber}` : ""}`
|
|
1407
|
+
: importName,
|
|
1408
|
+
);
|
|
1409
|
+
fileSignals.serviceRefs.add(service["bom-ref"]);
|
|
1410
|
+
if (fileSignals.fileRef) {
|
|
1411
|
+
service.fileRefs.add(fileSignals.fileRef);
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
if (classification.runtime) {
|
|
1415
|
+
fileSignals.runtimes.add(classification.runtime);
|
|
1416
|
+
}
|
|
1417
|
+
};
|
|
1418
|
+
|
|
1419
|
+
const scanUrlMatches = (
|
|
1420
|
+
raw,
|
|
1421
|
+
filePath,
|
|
1422
|
+
discoveryPath,
|
|
1423
|
+
fileSignals,
|
|
1424
|
+
servicesByKey,
|
|
1425
|
+
) => {
|
|
1426
|
+
for (const match of raw.matchAll(/https?:\/\/[^\s"'`)<]+/gu)) {
|
|
1427
|
+
const urlValue = sanitizeBomUrl(match[0]);
|
|
1428
|
+
if (!urlValue) {
|
|
1429
|
+
continue;
|
|
1430
|
+
}
|
|
1431
|
+
const provider = hostProviderFromValue(urlValue);
|
|
1432
|
+
if (!provider) {
|
|
1433
|
+
continue;
|
|
1434
|
+
}
|
|
1435
|
+
fileSignals.providers.add(provider);
|
|
1436
|
+
const service = ensureService(servicesByKey, provider, undefined);
|
|
1437
|
+
service.endpoints.add(urlValue);
|
|
1438
|
+
if (fileSignals.fileRef) {
|
|
1439
|
+
service.fileRefs.add(fileSignals.fileRef);
|
|
1440
|
+
}
|
|
1441
|
+
fileSignals.serviceRefs.add(service["bom-ref"]);
|
|
1442
|
+
appendOccurrence(
|
|
1443
|
+
service,
|
|
1444
|
+
relativeOccurrenceLocation(
|
|
1445
|
+
discoveryPath,
|
|
1446
|
+
filePath,
|
|
1447
|
+
lineNumberForIndex(raw, match.index),
|
|
1448
|
+
),
|
|
1449
|
+
);
|
|
1450
|
+
}
|
|
1451
|
+
};
|
|
1452
|
+
|
|
1453
|
+
const extractModelAssignments = (raw) => {
|
|
1454
|
+
const values = [];
|
|
1455
|
+
const patterns = [
|
|
1456
|
+
/\bmodel(?:Id|Name)?\s*[:=]\s*["'`]([^"'`\n]{2,160})["'`]/gu,
|
|
1457
|
+
/\b(?:model|model_name|model_id)\s*=\s*["'`]([^"'`\n]{2,160})["'`]/gu,
|
|
1458
|
+
/\b(?:model|model_name|model_id)\s*:\s*([A-Za-z0-9._:/-]{2,160})\b/gu,
|
|
1459
|
+
/pipeline\s*\(\s*["'`][^"'`]+["'`]\s*,\s*["'`]([^"'`\n]{2,160})["'`]/gu,
|
|
1460
|
+
/InferenceClient\s*\(\s*["'`]([^"'`\n]{2,160})["'`]/gu,
|
|
1461
|
+
/\b(?:from_pretrained|AutoModel(?:For\w+)?)\s*\(\s*["'`]([^"'`\n]{2,160})["'`]/gu,
|
|
1462
|
+
];
|
|
1463
|
+
for (const pattern of patterns) {
|
|
1464
|
+
for (const match of raw.matchAll(pattern)) {
|
|
1465
|
+
values.push({ index: match.index, value: match[1] });
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
return values.filter((entry) => {
|
|
1469
|
+
const normalized = String(entry.value || "").trim();
|
|
1470
|
+
return (
|
|
1471
|
+
normalized && !normalized.startsWith("http") && normalized !== "auto"
|
|
1472
|
+
);
|
|
1473
|
+
});
|
|
1474
|
+
};
|
|
1475
|
+
|
|
1476
|
+
const extractHuggingFaceReferences = (raw) => {
|
|
1477
|
+
const refs = [];
|
|
1478
|
+
const patterns = [
|
|
1479
|
+
/https?:\/\/huggingface\.co\/(datasets\/|spaces\/)?([^/"'`?#\s]+\/[^/"'`?#\s]+)(?:\/resolve\/[^"'`?#\s]+\/([^"'`?#\s]+))?/gu,
|
|
1480
|
+
/\b(?:repo_?id|model)\s*[:=]\s*["'`]([^"'`\n]+\/[^"'`\n]+)["'`]/gu,
|
|
1481
|
+
];
|
|
1482
|
+
for (const pattern of patterns) {
|
|
1483
|
+
for (const match of raw.matchAll(pattern)) {
|
|
1484
|
+
refs.push({
|
|
1485
|
+
index: match.index,
|
|
1486
|
+
artifact: match[3],
|
|
1487
|
+
sourceUrl: match[0]?.startsWith("http") ? match[0] : undefined,
|
|
1488
|
+
value:
|
|
1489
|
+
match[2] !== undefined ? `${match[1] || ""}${match[2]}` : match[1],
|
|
1490
|
+
});
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
return refs
|
|
1494
|
+
.map((entry) => {
|
|
1495
|
+
const reference = normalizeHuggingFaceReference(entry.value);
|
|
1496
|
+
return {
|
|
1497
|
+
artifact: entry.artifact,
|
|
1498
|
+
index: entry.index,
|
|
1499
|
+
reference,
|
|
1500
|
+
sourceUrl: entry.sourceUrl,
|
|
1501
|
+
};
|
|
1502
|
+
})
|
|
1503
|
+
.filter((entry) => entry.reference?.repoId);
|
|
1504
|
+
};
|
|
1505
|
+
|
|
1506
|
+
const applyOccurrenceEvidence = (subject, occurrences) => {
|
|
1507
|
+
if (!occurrences?.length) {
|
|
1508
|
+
return;
|
|
1509
|
+
}
|
|
1510
|
+
subject.evidence = subject.evidence || {};
|
|
1511
|
+
subject.evidence.occurrences = subject.evidence.occurrences || [];
|
|
1512
|
+
for (const occurrence of occurrences) {
|
|
1513
|
+
if (
|
|
1514
|
+
!subject.evidence.occurrences.some(
|
|
1515
|
+
(entry) => entry.location === occurrence.location,
|
|
1516
|
+
)
|
|
1517
|
+
) {
|
|
1518
|
+
subject.evidence.occurrences.push(occurrence);
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1521
|
+
};
|
|
1522
|
+
|
|
1523
|
+
const createModelComponent = (componentsByKey, seed, occurrenceLocation) => {
|
|
1524
|
+
const variants = normalizeDetectedVariants([
|
|
1525
|
+
...(seed.variants || []),
|
|
1526
|
+
...aiModelVariantsFromSeed(seed),
|
|
1527
|
+
]);
|
|
1528
|
+
const normalizedAssetType = ["dataset", "space"].includes(seed.assetType)
|
|
1529
|
+
? seed.assetType
|
|
1530
|
+
: "model";
|
|
1531
|
+
const key = `${normalizedAssetType}:${seed.provider || "ai"}:${seed.modelId}`;
|
|
1532
|
+
const component = ensureModelComponent(componentsByKey, key, seed);
|
|
1533
|
+
syncComponentProperties(component, {
|
|
1534
|
+
artifactFormat: seed.artifactFormat,
|
|
1535
|
+
confidence: seed.confidence,
|
|
1536
|
+
contextWindow: seed.contextWindow,
|
|
1537
|
+
kind: normalizedAssetType,
|
|
1538
|
+
modality: seed.modality,
|
|
1539
|
+
modelFamily: seed.modelFamily,
|
|
1540
|
+
parameterCount: seed.parameterCount,
|
|
1541
|
+
provider: seed.provider,
|
|
1542
|
+
quantization: seed.quantization,
|
|
1543
|
+
reviewNeeded: seed.reviewNeeded,
|
|
1544
|
+
runtime: seed.runtime,
|
|
1545
|
+
source: seed.source,
|
|
1546
|
+
});
|
|
1547
|
+
if (occurrenceLocation) {
|
|
1548
|
+
appendOccurrence(component.evidence, occurrenceLocation);
|
|
1549
|
+
}
|
|
1550
|
+
if (seed.tags?.length) {
|
|
1551
|
+
component.tags = [
|
|
1552
|
+
...new Set([...(component.tags || []), ...seed.tags, ...variants]),
|
|
1553
|
+
];
|
|
1554
|
+
}
|
|
1555
|
+
if (seed.externalReferences?.length) {
|
|
1556
|
+
component.externalReferences = [
|
|
1557
|
+
...new Map(
|
|
1558
|
+
[
|
|
1559
|
+
...(component.externalReferences || []),
|
|
1560
|
+
...seed.externalReferences,
|
|
1561
|
+
].map((reference) => [`${reference.type}:${reference.url}`, reference]),
|
|
1562
|
+
).values(),
|
|
1563
|
+
];
|
|
1564
|
+
}
|
|
1565
|
+
if (seed.licenses?.length && !component.licenses?.length) {
|
|
1566
|
+
component.licenses = seed.licenses;
|
|
1567
|
+
}
|
|
1568
|
+
if (!component.modelCard && seed.modelCard) {
|
|
1569
|
+
component.modelCard = sanitizeStructuredValueForBom(seed.modelCard);
|
|
1570
|
+
}
|
|
1571
|
+
const mergedPedigree = mergePedigreeVariants(
|
|
1572
|
+
component.pedigree || seed.pedigree,
|
|
1573
|
+
variants,
|
|
1574
|
+
);
|
|
1575
|
+
if (mergedPedigree) {
|
|
1576
|
+
component.pedigree = mergedPedigree;
|
|
1577
|
+
}
|
|
1578
|
+
if (!component.description && seed.description) {
|
|
1579
|
+
component.description = seed.description;
|
|
1580
|
+
}
|
|
1581
|
+
if (!component.version && seed.version) {
|
|
1582
|
+
component.version = seed.version;
|
|
1583
|
+
}
|
|
1584
|
+
return component;
|
|
1585
|
+
};
|
|
1586
|
+
|
|
1587
|
+
// -----------------------------------------------------------------------------
|
|
1588
|
+
// Section: artifact collectors (Modelfile and GGUF)
|
|
1589
|
+
// -----------------------------------------------------------------------------
|
|
1590
|
+
|
|
1591
|
+
const attachModelToServices = (servicesByKey, modelComponent, signals) => {
|
|
1592
|
+
const providers = signals.providers.size
|
|
1593
|
+
? Array.from(signals.providers)
|
|
1594
|
+
: [modelComponent.group].filter(Boolean);
|
|
1595
|
+
for (const provider of providers) {
|
|
1596
|
+
const service = ensureService(servicesByKey, provider, undefined);
|
|
1597
|
+
service.modelRefs.add(modelComponent["bom-ref"]);
|
|
1598
|
+
service.modelIds.add(modelComponent.name);
|
|
1599
|
+
const family = modelFamilyFromName(modelComponent.name);
|
|
1600
|
+
if (family) {
|
|
1601
|
+
service.modelFamilies.add(family);
|
|
1602
|
+
}
|
|
1603
|
+
for (const framework of signals.frameworks) {
|
|
1604
|
+
service.frameworks.add(framework);
|
|
1605
|
+
service.tags.add(framework);
|
|
1606
|
+
}
|
|
1607
|
+
for (const runtime of signals.runtimes) {
|
|
1608
|
+
service.runtimes.add(runtime);
|
|
1609
|
+
}
|
|
1610
|
+
if (signals.fileRef) {
|
|
1611
|
+
service.fileRefs.add(signals.fileRef);
|
|
1612
|
+
}
|
|
1613
|
+
signals.serviceRefs.add(service["bom-ref"]);
|
|
1614
|
+
}
|
|
1615
|
+
};
|
|
1616
|
+
|
|
1617
|
+
const collectTextAiInventory = (discoveryPath, options = {}, config = {}) => {
|
|
1618
|
+
const componentsByKey = new Map();
|
|
1619
|
+
const servicesByKey = new Map();
|
|
1620
|
+
const dependencyMap = new Map();
|
|
1621
|
+
const sourceFiles = getSourceFiles(
|
|
1622
|
+
discoveryPath,
|
|
1623
|
+
config.patterns || [],
|
|
1624
|
+
options,
|
|
1625
|
+
);
|
|
1626
|
+
for (const filePath of sourceFiles) {
|
|
1627
|
+
let raw = "";
|
|
1628
|
+
try {
|
|
1629
|
+
raw = readFileSync(filePath, "utf-8");
|
|
1630
|
+
} catch {
|
|
1631
|
+
continue;
|
|
1632
|
+
}
|
|
1633
|
+
const fileKey = relative(discoveryPath, filePath) || basename(filePath);
|
|
1634
|
+
const fileSignals = createFileSignals();
|
|
1635
|
+
if (config.fileKind) {
|
|
1636
|
+
fileSignals.fileRef = createAiFileComponent(
|
|
1637
|
+
componentsByKey,
|
|
1638
|
+
discoveryPath,
|
|
1639
|
+
filePath,
|
|
1640
|
+
config.fileKind,
|
|
1641
|
+
config.tags,
|
|
1642
|
+
)["bom-ref"];
|
|
1643
|
+
}
|
|
1644
|
+
scanUrlMatches(raw, filePath, discoveryPath, fileSignals, servicesByKey);
|
|
1645
|
+
for (const match of extractImportNames(raw)) {
|
|
1646
|
+
for (const importName of match.names) {
|
|
1647
|
+
appendImportSignals(
|
|
1648
|
+
importName,
|
|
1649
|
+
{
|
|
1650
|
+
fileName: fileKey,
|
|
1651
|
+
lineNumber: lineNumberForIndex(raw, match.index),
|
|
1652
|
+
},
|
|
1653
|
+
fileSignals,
|
|
1654
|
+
servicesByKey,
|
|
1655
|
+
);
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
for (const match of extractModelAssignments(raw)) {
|
|
1659
|
+
const modelId = String(match.value || "").trim();
|
|
1660
|
+
const provider =
|
|
1661
|
+
Array.from(fileSignals.providers)[0] || providerFromModelName(modelId);
|
|
1662
|
+
const component = createModelComponent(
|
|
1663
|
+
componentsByKey,
|
|
1664
|
+
{
|
|
1665
|
+
assetType: "model",
|
|
1666
|
+
confidence: "medium",
|
|
1667
|
+
kind: "model",
|
|
1668
|
+
modelFamily: modelFamilyFromName(modelId),
|
|
1669
|
+
modelId,
|
|
1670
|
+
provider,
|
|
1671
|
+
reviewNeeded: provider === "ollama",
|
|
1672
|
+
runtime: Array.from(fileSignals.runtimes)[0],
|
|
1673
|
+
source: "source-code-analysis",
|
|
1674
|
+
tags: [...fileSignals.frameworks],
|
|
1675
|
+
},
|
|
1676
|
+
relativeOccurrenceLocation(
|
|
1677
|
+
discoveryPath,
|
|
1678
|
+
filePath,
|
|
1679
|
+
lineNumberForIndex(raw, match.index),
|
|
1680
|
+
),
|
|
1681
|
+
);
|
|
1682
|
+
fileSignals.modelRefs.add(component["bom-ref"]);
|
|
1683
|
+
attachModelToServices(servicesByKey, component, fileSignals);
|
|
1684
|
+
}
|
|
1685
|
+
for (const match of extractHuggingFaceReferences(raw)) {
|
|
1686
|
+
const occurrenceLocation = relativeOccurrenceLocation(
|
|
1687
|
+
discoveryPath,
|
|
1688
|
+
filePath,
|
|
1689
|
+
lineNumberForIndex(raw, match.index),
|
|
1690
|
+
);
|
|
1691
|
+
const assetType = match.reference.assetType;
|
|
1692
|
+
const [group, name] = match.reference.repoId.split("/");
|
|
1693
|
+
const artifactDetails = extractHuggingFaceArtifactDetails(
|
|
1694
|
+
match.sourceUrl,
|
|
1695
|
+
);
|
|
1696
|
+
const component = createModelComponent(
|
|
1697
|
+
componentsByKey,
|
|
1698
|
+
{
|
|
1699
|
+
assetType,
|
|
1700
|
+
artifactFormat: artifactDetails.artifactFormat,
|
|
1701
|
+
confidence: "high",
|
|
1702
|
+
externalReferences: [
|
|
1703
|
+
{
|
|
1704
|
+
type: "distribution",
|
|
1705
|
+
url:
|
|
1706
|
+
artifactDetails.sourceUrl ||
|
|
1707
|
+
toHuggingFaceAssetUrl(assetType, match.reference.repoId),
|
|
1708
|
+
},
|
|
1709
|
+
],
|
|
1710
|
+
modelFamily:
|
|
1711
|
+
assetType === "model" ? modelFamilyFromName(name) : undefined,
|
|
1712
|
+
modelId: match.reference.repoId,
|
|
1713
|
+
provider: "huggingface",
|
|
1714
|
+
quantization: artifactDetails.quantization,
|
|
1715
|
+
source: "source-code-analysis",
|
|
1716
|
+
tags: ["huggingface", assetType],
|
|
1717
|
+
version: match.reference.version,
|
|
1718
|
+
},
|
|
1719
|
+
occurrenceLocation,
|
|
1720
|
+
);
|
|
1721
|
+
component.group = group;
|
|
1722
|
+
component.name = name;
|
|
1723
|
+
fileSignals.modelRefs.add(component["bom-ref"]);
|
|
1724
|
+
attachModelToServices(servicesByKey, component, fileSignals);
|
|
1725
|
+
}
|
|
1726
|
+
if (fileSignals.fileRef) {
|
|
1727
|
+
const fileDeps = new Set([
|
|
1728
|
+
...fileSignals.modelRefs,
|
|
1729
|
+
...fileSignals.serviceRefs,
|
|
1730
|
+
]);
|
|
1731
|
+
if (fileDeps.size) {
|
|
1732
|
+
dependencyMap.set(fileSignals.fileRef, fileDeps);
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
}
|
|
1736
|
+
return { componentsByKey, dependencyMap, servicesByKey };
|
|
1737
|
+
};
|
|
1738
|
+
|
|
1739
|
+
const collectConfiguredTextAiInventory = (discoveryPath, options, config) => {
|
|
1740
|
+
const { componentsByKey, dependencyMap, servicesByKey } =
|
|
1741
|
+
collectTextAiInventory(discoveryPath, options, config);
|
|
1742
|
+
return buildAiInventoryResult(componentsByKey, servicesByKey, dependencyMap);
|
|
1743
|
+
};
|
|
1744
|
+
|
|
1745
|
+
// -----------------------------------------------------------------------------
|
|
1746
|
+
// Section: inventory collectors
|
|
1747
|
+
// -----------------------------------------------------------------------------
|
|
1748
|
+
|
|
1749
|
+
/**
|
|
1750
|
+
* Collect AI-related inventory from JavaScript and TypeScript sources.
|
|
1751
|
+
*
|
|
1752
|
+
* @param {string} discoveryPath directory or file being analyzed
|
|
1753
|
+
* @param {Object} [options={}] collection options
|
|
1754
|
+
* @returns {{ components: Object[], dependencies: Object[], services: Object[] }} AI inventory
|
|
1755
|
+
*/
|
|
1756
|
+
export function collectJsAiInventory(discoveryPath, options = {}) {
|
|
1757
|
+
const { componentsByKey, dependencyMap, servicesByKey } =
|
|
1758
|
+
collectTextAiInventory(
|
|
1759
|
+
discoveryPath,
|
|
1760
|
+
options,
|
|
1761
|
+
TEXT_AI_INVENTORY_CONFIGS.javascript,
|
|
1762
|
+
);
|
|
1763
|
+
for (const filePath of getMatchingFiles(
|
|
1764
|
+
discoveryPath,
|
|
1765
|
+
MODEFILE_PATTERNS,
|
|
1766
|
+
options,
|
|
1767
|
+
)) {
|
|
1768
|
+
let raw = "";
|
|
1769
|
+
try {
|
|
1770
|
+
raw = readFileSync(filePath, "utf-8");
|
|
1771
|
+
} catch {
|
|
1772
|
+
continue;
|
|
1773
|
+
}
|
|
1774
|
+
const parsed = parseOllamaModelfile(raw);
|
|
1775
|
+
if (!parsed.from) {
|
|
1776
|
+
continue;
|
|
1777
|
+
}
|
|
1778
|
+
const modelId = parsed.from.replace(/^FROM\s+/iu, "").trim();
|
|
1779
|
+
const fileComponent = createAiFileComponent(
|
|
1780
|
+
componentsByKey,
|
|
1781
|
+
discoveryPath,
|
|
1782
|
+
filePath,
|
|
1783
|
+
"model-config-file",
|
|
1784
|
+
["ollama", "modelfile"],
|
|
1785
|
+
);
|
|
1786
|
+
const component = createModelComponent(
|
|
1787
|
+
componentsByKey,
|
|
1788
|
+
{
|
|
1789
|
+
artifactFormat: "modelfile",
|
|
1790
|
+
confidence: "high",
|
|
1791
|
+
licenses: getLicenses({ license: parsed.license }),
|
|
1792
|
+
modelFamily: modelFamilyFromName(modelId),
|
|
1793
|
+
modelId,
|
|
1794
|
+
provider: normalizeHuggingFaceReference(modelId)
|
|
1795
|
+
? "huggingface"
|
|
1796
|
+
: "ollama",
|
|
1797
|
+
reviewNeeded: true,
|
|
1798
|
+
runtime: "ollama",
|
|
1799
|
+
source: "local-config",
|
|
1800
|
+
tags: ["ollama", "modelfile"],
|
|
1801
|
+
},
|
|
1802
|
+
relativeOccurrenceLocation(discoveryPath, filePath),
|
|
1803
|
+
);
|
|
1804
|
+
dependencyMap.set(
|
|
1805
|
+
fileComponent["bom-ref"],
|
|
1806
|
+
new Set([component["bom-ref"]]),
|
|
1807
|
+
);
|
|
1808
|
+
attachModelToServices(servicesByKey, component, {
|
|
1809
|
+
fileRef: fileComponent["bom-ref"],
|
|
1810
|
+
frameworks: new Set(),
|
|
1811
|
+
modelRefs: new Set([component["bom-ref"]]),
|
|
1812
|
+
providers: new Set(["ollama"]),
|
|
1813
|
+
runtimes: new Set(["ollama"]),
|
|
1814
|
+
serviceRefs: new Set(),
|
|
1815
|
+
});
|
|
1816
|
+
}
|
|
1817
|
+
for (const filePath of getMatchingFiles(
|
|
1818
|
+
discoveryPath,
|
|
1819
|
+
GGUF_PATTERNS,
|
|
1820
|
+
options,
|
|
1821
|
+
)) {
|
|
1822
|
+
let metadata;
|
|
1823
|
+
try {
|
|
1824
|
+
metadata = readGgufMetadata(filePath);
|
|
1825
|
+
} catch {
|
|
1826
|
+
continue;
|
|
1827
|
+
}
|
|
1828
|
+
const fileComponent = createAiFileComponent(
|
|
1829
|
+
componentsByKey,
|
|
1830
|
+
discoveryPath,
|
|
1831
|
+
filePath,
|
|
1832
|
+
"model-artifact-file",
|
|
1833
|
+
["gguf"],
|
|
1834
|
+
);
|
|
1835
|
+
const parsedFileName = parseGgufFilename(filePath);
|
|
1836
|
+
const contextWindow = contextWindowFromGgufMetadata(metadata);
|
|
1837
|
+
const quantization =
|
|
1838
|
+
ggufFileTypeName(metadata["general.file_type"]) ||
|
|
1839
|
+
parsedFileName?.encoding ||
|
|
1840
|
+
quantizationValueFromFilename(filePath);
|
|
1841
|
+
applyGgufProperties(fileComponent, metadata, parsedFileName, true);
|
|
1842
|
+
const component = createModelComponent(
|
|
1843
|
+
componentsByKey,
|
|
1844
|
+
{
|
|
1845
|
+
artifactFormat: "gguf",
|
|
1846
|
+
confidence: "high",
|
|
1847
|
+
contextWindow,
|
|
1848
|
+
description: metadata["general.description"],
|
|
1849
|
+
externalReferences: createGgufExternalReferences(metadata),
|
|
1850
|
+
licenses: getLicenses({ license: metadata["general.license"] }),
|
|
1851
|
+
modelCard: createGgufModelCard(metadata, parsedFileName),
|
|
1852
|
+
modelFamily: modelFamilyFromName(
|
|
1853
|
+
metadata["general.name"] ||
|
|
1854
|
+
metadata["general.basename"] ||
|
|
1855
|
+
ggufModelIdFromFilename(parsedFileName, filePath),
|
|
1856
|
+
),
|
|
1857
|
+
modelId:
|
|
1858
|
+
metadata["general.name"] ||
|
|
1859
|
+
ggufModelIdFromFilename(parsedFileName, filePath),
|
|
1860
|
+
parameterCount: metadata["general.parameter_count"],
|
|
1861
|
+
pedigree: createGgufPedigree(metadata),
|
|
1862
|
+
provider: metadata["general.organization"] || "local",
|
|
1863
|
+
quantization,
|
|
1864
|
+
reviewNeeded: true,
|
|
1865
|
+
runtime: "llama.cpp",
|
|
1866
|
+
source: "local-artifact",
|
|
1867
|
+
tags: [
|
|
1868
|
+
"gguf",
|
|
1869
|
+
"local-model",
|
|
1870
|
+
...(Array.isArray(metadata["general.tags"])
|
|
1871
|
+
? metadata["general.tags"]
|
|
1872
|
+
: []
|
|
1873
|
+
).filter(Boolean),
|
|
1874
|
+
parsedFileName?.sidecar,
|
|
1875
|
+
parsedFileName?.type,
|
|
1876
|
+
].filter(Boolean),
|
|
1877
|
+
variants:
|
|
1878
|
+
parsedFileName?.type === "LoRA"
|
|
1879
|
+
? ["adapter"]
|
|
1880
|
+
: parsedFileName?.sidecar
|
|
1881
|
+
? [parsedFileName.sidecar]
|
|
1882
|
+
: undefined,
|
|
1883
|
+
version: metadata["general.version"] || parsedFileName?.version,
|
|
1884
|
+
},
|
|
1885
|
+
relativeOccurrenceLocation(discoveryPath, filePath),
|
|
1886
|
+
);
|
|
1887
|
+
applyGgufProperties(component, metadata, parsedFileName, false);
|
|
1888
|
+
dependencyMap.set(
|
|
1889
|
+
fileComponent["bom-ref"],
|
|
1890
|
+
new Set([component["bom-ref"]]),
|
|
1891
|
+
);
|
|
1892
|
+
}
|
|
1893
|
+
|
|
1894
|
+
return buildAiInventoryResult(componentsByKey, servicesByKey, dependencyMap);
|
|
1895
|
+
}
|
|
1896
|
+
|
|
1897
|
+
/**
|
|
1898
|
+
* Collect AI inventory from local Hugging Face repository metadata files.
|
|
1899
|
+
*
|
|
1900
|
+
* @param {string} discoveryPath directory or file being analyzed
|
|
1901
|
+
* @param {Object} [options={}] collection options
|
|
1902
|
+
* @returns {{ components: Object[], dependencies: Object[], services: Object[] }} AI inventory
|
|
1903
|
+
*/
|
|
1904
|
+
export function collectHuggingFaceRepoAiInventory(discoveryPath, options = {}) {
|
|
1905
|
+
const componentsByKey = new Map();
|
|
1906
|
+
const dependencyMap = new Map();
|
|
1907
|
+
const repoMetadata = new Map();
|
|
1908
|
+
const rememberRepoEntry = (filePath) => {
|
|
1909
|
+
const directoryPath = dirname(filePath);
|
|
1910
|
+
if (!repoMetadata.has(directoryPath)) {
|
|
1911
|
+
repoMetadata.set(directoryPath, {
|
|
1912
|
+
adapterConfig: undefined,
|
|
1913
|
+
cardData: undefined,
|
|
1914
|
+
config: undefined,
|
|
1915
|
+
files: new Set(),
|
|
1916
|
+
});
|
|
1917
|
+
}
|
|
1918
|
+
repoMetadata.get(directoryPath).files.add(filePath);
|
|
1919
|
+
return repoMetadata.get(directoryPath);
|
|
1920
|
+
};
|
|
1921
|
+
|
|
1922
|
+
for (const filePath of getMatchingFiles(
|
|
1923
|
+
discoveryPath,
|
|
1924
|
+
HUGGING_FACE_MODEL_CARD_PATTERNS,
|
|
1925
|
+
options,
|
|
1926
|
+
)) {
|
|
1927
|
+
let raw = "";
|
|
1928
|
+
try {
|
|
1929
|
+
raw = readFileSync(filePath, "utf-8");
|
|
1930
|
+
} catch {
|
|
1931
|
+
continue;
|
|
1932
|
+
}
|
|
1933
|
+
const cardData = parseHuggingFaceReadmeFrontmatter(raw);
|
|
1934
|
+
if (!hasHuggingFaceCardSignals(cardData)) {
|
|
1935
|
+
continue;
|
|
1936
|
+
}
|
|
1937
|
+
rememberRepoEntry(filePath).cardData = cardData;
|
|
1938
|
+
}
|
|
1939
|
+
|
|
1940
|
+
for (const filePath of getMatchingFiles(
|
|
1941
|
+
discoveryPath,
|
|
1942
|
+
HUGGING_FACE_CONFIG_PATTERNS,
|
|
1943
|
+
options,
|
|
1944
|
+
)) {
|
|
1945
|
+
const config = parseJsonObject(filePath);
|
|
1946
|
+
if (
|
|
1947
|
+
!config?.model_type &&
|
|
1948
|
+
!config?.architectures &&
|
|
1949
|
+
!config?.quantization_config &&
|
|
1950
|
+
!config?.max_position_embeddings
|
|
1951
|
+
) {
|
|
1952
|
+
continue;
|
|
1953
|
+
}
|
|
1954
|
+
rememberRepoEntry(filePath).config = config;
|
|
1955
|
+
}
|
|
1956
|
+
|
|
1957
|
+
for (const filePath of getMatchingFiles(
|
|
1958
|
+
discoveryPath,
|
|
1959
|
+
HUGGING_FACE_ADAPTER_PATTERNS,
|
|
1960
|
+
options,
|
|
1961
|
+
)) {
|
|
1962
|
+
const adapterConfig = parseJsonObject(filePath);
|
|
1963
|
+
if (!adapterConfig?.base_model_name_or_path && !adapterConfig?.peft_type) {
|
|
1964
|
+
continue;
|
|
1965
|
+
}
|
|
1966
|
+
rememberRepoEntry(filePath).adapterConfig = adapterConfig;
|
|
1967
|
+
}
|
|
1968
|
+
|
|
1969
|
+
for (const [directoryPath, metadata] of repoMetadata.entries()) {
|
|
1970
|
+
const repoId =
|
|
1971
|
+
normalizeHuggingFaceReference(metadata.cardData?.modelId)?.repoId ||
|
|
1972
|
+
normalizeHuggingFaceReference(metadata.cardData?.model_id)?.repoId ||
|
|
1973
|
+
normalizeHuggingFaceReference(metadata.cardData?.id)?.repoId ||
|
|
1974
|
+
normalizeHuggingFaceReference(metadata.config?._name_or_path)?.repoId ||
|
|
1975
|
+
repoIdFromFixtureDirectory(Array.from(metadata.files)[0]);
|
|
1976
|
+
const modelId = repoId || basename(directoryPath);
|
|
1977
|
+
const quantization =
|
|
1978
|
+
quantizationValueFromConfig(metadata.config?.quantization_config) ||
|
|
1979
|
+
metadata.cardData?.quantization ||
|
|
1980
|
+
metadata.cardData?.quantization_config;
|
|
1981
|
+
const modelOccurrenceLocation = relativeOccurrenceLocation(
|
|
1982
|
+
discoveryPath,
|
|
1983
|
+
Array.from(metadata.files)[0],
|
|
1984
|
+
);
|
|
1985
|
+
const modelCard = createHuggingFaceModelCard(
|
|
1986
|
+
metadata.cardData,
|
|
1987
|
+
metadata.config,
|
|
1988
|
+
(dataset) => {
|
|
1989
|
+
const datasetReference = createHuggingFaceDatasetReference(dataset, {
|
|
1990
|
+
componentSource: "local-huggingface-metadata",
|
|
1991
|
+
componentTags: ["ai", "dataset", "huggingface"],
|
|
1992
|
+
urlSanitizer: sanitizeBomUrl,
|
|
1993
|
+
});
|
|
1994
|
+
if (!datasetReference) {
|
|
1995
|
+
return undefined;
|
|
1996
|
+
}
|
|
1997
|
+
const datasetComponent = ensureModelComponent(
|
|
1998
|
+
componentsByKey,
|
|
1999
|
+
`dataset:${datasetReference.modelId}`,
|
|
2000
|
+
{
|
|
2001
|
+
assetType: "dataset",
|
|
2002
|
+
description: datasetReference.description,
|
|
2003
|
+
externalReferences: datasetReference.externalReferences,
|
|
2004
|
+
modelId: datasetReference.modelId,
|
|
2005
|
+
provider: datasetReference.provider,
|
|
2006
|
+
},
|
|
2007
|
+
);
|
|
2008
|
+
datasetComponent.group = datasetReference.group;
|
|
2009
|
+
datasetComponent.name = datasetReference.name;
|
|
2010
|
+
datasetComponent.purl = datasetReference.purl;
|
|
2011
|
+
datasetComponent.data = datasetReference.component.data;
|
|
2012
|
+
datasetComponent.tags = [
|
|
2013
|
+
...new Set([
|
|
2014
|
+
...(datasetComponent.tags || []),
|
|
2015
|
+
"ai",
|
|
2016
|
+
"dataset",
|
|
2017
|
+
"huggingface",
|
|
2018
|
+
]),
|
|
2019
|
+
];
|
|
2020
|
+
datasetComponent.properties =
|
|
2021
|
+
datasetReference.component.properties || [];
|
|
2022
|
+
applyOccurrenceEvidence(datasetComponent, [
|
|
2023
|
+
{ location: modelOccurrenceLocation },
|
|
2024
|
+
]);
|
|
2025
|
+
if (!dependencyMap.has(modelId)) {
|
|
2026
|
+
dependencyMap.set(modelId, new Set());
|
|
2027
|
+
}
|
|
2028
|
+
dependencyMap.get(modelId).add(datasetComponent["bom-ref"]);
|
|
2029
|
+
return datasetReference.ref;
|
|
2030
|
+
},
|
|
2031
|
+
{ urlSanitizer: sanitizeBomUrl },
|
|
2032
|
+
);
|
|
2033
|
+
const pedigree = createHuggingFacePedigree(
|
|
2034
|
+
metadata.cardData,
|
|
2035
|
+
metadata.adapterConfig,
|
|
2036
|
+
quantization,
|
|
2037
|
+
);
|
|
2038
|
+
const variants = detectAiModelVariants({
|
|
2039
|
+
description:
|
|
2040
|
+
metadata.cardData?.model_description || metadata.cardData?.description,
|
|
2041
|
+
metadata: [
|
|
2042
|
+
metadata.adapterConfig?.peft_type,
|
|
2043
|
+
metadata.cardData?.library_name,
|
|
2044
|
+
],
|
|
2045
|
+
modelName: modelId,
|
|
2046
|
+
notes: [pedigree?.notes],
|
|
2047
|
+
quantization,
|
|
2048
|
+
relation:
|
|
2049
|
+
metadata.cardData?.base_model_relation ||
|
|
2050
|
+
metadata.adapterConfig?.base_model_relation ||
|
|
2051
|
+
(metadata.adapterConfig?.base_model_name_or_path
|
|
2052
|
+
? "adapter"
|
|
2053
|
+
: undefined),
|
|
2054
|
+
tags: metadata.cardData?.tags,
|
|
2055
|
+
});
|
|
2056
|
+
const component = createModelComponent(
|
|
2057
|
+
componentsByKey,
|
|
2058
|
+
{
|
|
2059
|
+
assetType: "model",
|
|
2060
|
+
confidence: "high",
|
|
2061
|
+
contextWindow: metadata.config?.max_position_embeddings,
|
|
2062
|
+
description:
|
|
2063
|
+
metadata.cardData?.model_description ||
|
|
2064
|
+
metadata.cardData?.description,
|
|
2065
|
+
externalReferences: repoId
|
|
2066
|
+
? [{ type: "distribution", url: `https://huggingface.co/${repoId}` }]
|
|
2067
|
+
: [],
|
|
2068
|
+
licenses: getLicenses({ license: metadata.cardData?.license }),
|
|
2069
|
+
modelCard,
|
|
2070
|
+
modelFamily: modelFamilyFromName(modelId),
|
|
2071
|
+
modelId,
|
|
2072
|
+
pedigree,
|
|
2073
|
+
provider: "huggingface",
|
|
2074
|
+
quantization,
|
|
2075
|
+
variants,
|
|
2076
|
+
runtime: metadata.cardData?.library_name,
|
|
2077
|
+
source: "local-huggingface-metadata",
|
|
2078
|
+
tags: ["huggingface", "model-repo", ...(metadata.cardData?.tags || [])],
|
|
2079
|
+
},
|
|
2080
|
+
modelOccurrenceLocation,
|
|
2081
|
+
);
|
|
2082
|
+
if (dependencyMap.has(modelId)) {
|
|
2083
|
+
dependencyMap.set(component["bom-ref"], dependencyMap.get(modelId));
|
|
2084
|
+
dependencyMap.delete(modelId);
|
|
2085
|
+
}
|
|
2086
|
+
for (const filePath of metadata.files) {
|
|
2087
|
+
appendOccurrence(
|
|
2088
|
+
component.evidence,
|
|
2089
|
+
relativeOccurrenceLocation(discoveryPath, filePath),
|
|
2090
|
+
);
|
|
2091
|
+
}
|
|
2092
|
+
}
|
|
2093
|
+
|
|
2094
|
+
return buildAiInventoryResult(componentsByKey, new Map(), dependencyMap);
|
|
2095
|
+
}
|
|
2096
|
+
|
|
2097
|
+
/**
|
|
2098
|
+
* Collect AI-related inventory from Python sources.
|
|
2099
|
+
*
|
|
2100
|
+
* @param {string} discoveryPath directory or file being analyzed
|
|
2101
|
+
* @param {Object} [options={}] collection options
|
|
2102
|
+
* @returns {{ components: Object[], dependencies: Object[], services: Object[] }} AI inventory
|
|
2103
|
+
*/
|
|
2104
|
+
export function collectPythonAiInventory(discoveryPath, options = {}) {
|
|
2105
|
+
return collectConfiguredTextAiInventory(
|
|
2106
|
+
discoveryPath,
|
|
2107
|
+
options,
|
|
2108
|
+
TEXT_AI_INVENTORY_CONFIGS.python,
|
|
2109
|
+
);
|
|
2110
|
+
}
|
|
2111
|
+
|
|
2112
|
+
/**
|
|
2113
|
+
* Collect AI-related inventory from notebook sources.
|
|
2114
|
+
*
|
|
2115
|
+
* @param {string} discoveryPath directory or file being analyzed
|
|
2116
|
+
* @param {Object} [options={}] collection options
|
|
2117
|
+
* @returns {{ components: Object[], dependencies: Object[], services: Object[] }} AI inventory
|
|
2118
|
+
*/
|
|
2119
|
+
export function collectNotebookAiInventory(discoveryPath, options = {}) {
|
|
2120
|
+
return collectConfiguredTextAiInventory(
|
|
2121
|
+
discoveryPath,
|
|
2122
|
+
options,
|
|
2123
|
+
TEXT_AI_INVENTORY_CONFIGS.notebook,
|
|
2124
|
+
);
|
|
2125
|
+
}
|
|
2126
|
+
|
|
2127
|
+
/**
|
|
2128
|
+
* Collect AI-related inventory from prompt and agent configuration files.
|
|
2129
|
+
*
|
|
2130
|
+
* @param {string} discoveryPath directory or file being analyzed
|
|
2131
|
+
* @param {Object} [options={}] collection options
|
|
2132
|
+
* @returns {{ components: Object[], dependencies: Object[], services: Object[] }} AI inventory
|
|
2133
|
+
*/
|
|
2134
|
+
export function collectPromptConfigAiInventory(discoveryPath, options = {}) {
|
|
2135
|
+
return collectConfiguredTextAiInventory(
|
|
2136
|
+
discoveryPath,
|
|
2137
|
+
options,
|
|
2138
|
+
TEXT_AI_INVENTORY_CONFIGS.promptConfig,
|
|
2139
|
+
);
|
|
2140
|
+
}
|