Brunobkr/llama.cpp_AlgMor24_github
ΩFFFΣLLIa • llama.cpp • AlgMor24 ██████╗ ███████╗███████╗███████╗██╗ ██╗ ██╗ █████╗ ██╔═══██╗██╔════╝██╔════╝██╔════╝██║ ██║ ██║██╔══██╗ ██║ ██║█████╗ █████╗ █████╗ ██║ ██║ ██║███████║ ██║ ██║██╔══╝ ██╔══╝ ██╔══╝ ██║ ██║ ██║██╔══██║ ╚██████╔╝██║ ██║ ███████╗███████╗███████╗██║██║ ██║ ╚═════╝ ╚═╝ ╚═╝ ╚══════╝╚══════╝╚══════╝╚═╝╚═╝ ╚═╝ High-Performance LLM / VLM Inference & Autonomous Agentic Ecosystem… See the full description on the dataset page: https://huggingface.co/datasets/Brunobkr/llama.cpp_AlgMor24_github.
03.1k
1'use strict'2 3const { normalizeIPv6, removeDotSegments, recomposeAuthority, normalizePercentEncoding, normalizePathEncoding, escapePreservingEscapes, reescapeHostDelimiters, isIPv4, nonSimpleDomain } = require('./lib/utils')4const { SCHEMES, getSchemeHandler } = require('./lib/schemes')5 6/**7 * @template {import('./types/index').URIComponent|string} T8 * @param {T} uri9 * @param {import('./types/index').Options} [options]10 * @returns {T}11 */12function normalize (uri, options) {13 if (typeof uri === 'string') {14 uri = /** @type {T} */ (normalizeString(uri, options))15 } else if (typeof uri === 'object') {16 uri = /** @type {T} */ (parse(serialize(uri, options), options))17 }18 return uri19}20 21/**22 * @param {string} baseURI23 * @param {string} relativeURI24 * @param {import('./types/index').Options} [options]25 * @returns {string}26 */27function resolve (baseURI, relativeURI, options) {28 const schemelessOptions = options ? Object.assign({ scheme: 'null' }, options) : { scheme: 'null' }29 const { parsed: baseParsed, malformedAuthorityOrPort: baseMalformed } = parseWithStatus(baseURI, schemelessOptions)30 const { parsed: relativeParsed, malformedAuthorityOrPort: relativeMalformed } = parseWithStatus(relativeURI, schemelessOptions)31 if (baseMalformed || relativeMalformed) {32 throw new Error(baseParsed.error || relativeParsed.error || 'URI is malformed.')33 }34 const resolved = resolveComponent(baseParsed, relativeParsed, schemelessOptions, true)35 schemelessOptions.skipEscape = true36 return serialize(resolved, schemelessOptions)37}38 39/**40 * @param {import ('./types/index').URIComponent} base41 * @param {import ('./types/index').URIComponent} relative42 * @param {import('./types/index').Options} [options]43 * @param {boolean} [skipNormalization=false]44 * @returns {import ('./types/index').URIComponent}45 */46function resolveComponent (base, relative, options, skipNormalization) {47 /** @type {import('./types/index').URIComponent} */48 const target = {}49 if (!skipNormalization) {50 base = parse(serialize(base, options), options) // normalize base component51 relative = parse(serialize(relative, options), options) // normalize relative component52 }53 options = options || {}54 55 if (!options.tolerant && relative.scheme) {56 target.scheme = relative.scheme57 // target.authority = relative.authority;58 target.userinfo = relative.userinfo59 target.host = relative.host60 target.port = relative.port61 target.path = removeDotSegments(relative.path || '')62 target.query = relative.query63 } else {64 if (relative.userinfo !== undefined || relative.host !== undefined || relative.port !== undefined) {65 // target.authority = relative.authority;66 target.userinfo = relative.userinfo67 target.host = relative.host68 target.port = relative.port69 target.path = removeDotSegments(relative.path || '')70 target.query = relative.query71 } else {72 if (!relative.path) {73 target.path = base.path74 if (relative.query !== undefined) {75 target.query = relative.query76 } else {77 target.query = base.query78 }79 } else {80 if (relative.path[0] === '/') {81 target.path = removeDotSegments(relative.path)82 } else {83 if ((base.userinfo !== undefined || base.host !== undefined || base.port !== undefined) && !base.path) {84 target.path = '/' + relative.path85 } else if (!base.path) {86 target.path = relative.path87 } else {88 target.path = base.path.slice(0, base.path.lastIndexOf('/') + 1) + relative.path89 }90 target.path = removeDotSegments(target.path)91 }92 target.query = relative.query93 }94 // target.authority = base.authority;95 target.userinfo = base.userinfo96 target.host = base.host97 target.port = base.port98 }99 target.scheme = base.scheme100 }101 102 target.fragment = relative.fragment103 104 return target105}106 107/**108 * @param {import ('./types/index').URIComponent|string} uriA109 * @param {import ('./types/index').URIComponent|string} uriB110 * @param {import ('./types/index').Options} options111 * @returns {boolean}112 */113function equal (uriA, uriB, options) {114 const normalizedA = normalizeComparableURI(uriA, options)115 const normalizedB = normalizeComparableURI(uriB, options)116 117 return normalizedA !== undefined && normalizedB !== undefined && normalizedA.toLowerCase() === normalizedB.toLowerCase()118}119 120/**121 * @param {Readonly<import('./types/index').URIComponent>} cmpts122 * @param {import('./types/index').Options} [opts]123 * @returns {string}124 */125function serialize (cmpts, opts) {126 const component = {127 host: cmpts.host,128 scheme: cmpts.scheme,129 userinfo: cmpts.userinfo,130 port: cmpts.port,131 path: cmpts.path,132 query: cmpts.query,133 nid: cmpts.nid,134 nss: cmpts.nss,135 uuid: cmpts.uuid,136 fragment: cmpts.fragment,137 reference: cmpts.reference,138 resourceName: cmpts.resourceName,139 secure: cmpts.secure,140 error: ''141 }142 const options = Object.assign({}, opts)143 const uriTokens = []144 145 // find scheme handler146 const schemeHandler = getSchemeHandler(options.scheme || component.scheme)147 148 // perform scheme specific serialization149 if (schemeHandler && schemeHandler.serialize) schemeHandler.serialize(component, options)150 151 if (component.path !== undefined) {152 if (!options.skipEscape) {153 component.path = escapePreservingEscapes(component.path)154 155 if (component.scheme !== undefined) {156 component.path = component.path.split('%3A').join(':')157 }158 } else {159 component.path = normalizePercentEncoding(component.path)160 }161 }162 163 if (options.reference !== 'suffix' && component.scheme) {164 uriTokens.push(component.scheme, ':')165 }166 167 const authority = recomposeAuthority(component)168 if (authority !== undefined) {169 if (options.reference !== 'suffix') {170 uriTokens.push('//')171 }172 173 uriTokens.push(authority)174 175 if (component.path && component.path[0] !== '/') {176 uriTokens.push('/')177 }178 }179 if (component.path !== undefined) {180 let s = component.path181 182 if (!options.absolutePath && (!schemeHandler || !schemeHandler.absolutePath)) {183 s = removeDotSegments(s)184 }185 186 if (187 authority === undefined &&188 s[0] === '/' &&189 s[1] === '/'190 ) {191 // don't allow the path to start with "//"192 s = '/%2F' + s.slice(2)193 }194 195 uriTokens.push(s)196 }197 198 if (component.query !== undefined) {199 uriTokens.push('?', component.query)200 }201 202 if (component.fragment !== undefined) {203 uriTokens.push('#', component.fragment)204 }205 return uriTokens.join('')206}207 208const URI_PARSE = /^(?:([^#/:?]+):)?(?:\/\/((?:([^#/?@]*)@)?(\[[^#/?\]]+\]|[^#/:?]*)(?::(\d*))?))?([^#?]*)(?:\?([^#]*))?(?:#((?:.|[\n\r])*))?/u209 210// Captures the authority component (between "//" and the next "/", "?" or "#"),211// with or without a scheme prefix, for the literal-backslash rejection below.212const AUTHORITY_PREFIX = /^(?:[^#/:?]+:)?\/\/([^/?#]*)/213 214// Captures the leading authority-introducer region after an optional scheme: a215// run of forward slashes, backslashes, and the characters the WHATWG URL parser216// removes before parsing (TAB U+0009, LF U+000A, CR U+000D). A valid introducer217// is exactly "//". Node treats "\" as "/" on special schemes and strips those218// characters first, so forms like "\\", "/\", "\/", "/<TAB>/", or a leading219// "<TAB>//" reach an authority in Node while fast-uri's URI_PARSE folds them into220// the path group (host confusion / SSRF / redirect bypass).221const AUTHORITY_INTRODUCER_REGION = /^(?:[^#/:?]+:)?([/\\\t\n\r]*)/222 223/**224 * @param {import('./types/index').URIComponent} parsed225 * @param {RegExpMatchArray} matches226 * @returns {string|undefined}227 */228function getParseError (parsed, matches) {229 if (matches[2] !== undefined && parsed.path && parsed.path[0] !== '/') {230 return 'URI path must start with "/" when authority is present.'231 }232 233 if (typeof parsed.port === 'number' && (parsed.port < 0 || parsed.port > 65535)) {234 return 'URI port is malformed.'235 }236 237 return undefined238}239 240/**241 * @param {string} uri242 * @param {import('./types/index').Options} [opts]243 * @returns {{ parsed: import('./types/index').URIComponent, malformedAuthorityOrPort: boolean }}244 */245function parseWithStatus (uri, opts) {246 const options = Object.assign({}, opts)247 /** @type {import('./types/index').URIComponent} */248 const parsed = {249 scheme: undefined,250 userinfo: undefined,251 host: '',252 port: undefined,253 path: '',254 query: undefined,255 fragment: undefined256 }257 258 let malformedAuthorityOrPort = false259 260 let isIP = false261 if (options.reference === 'suffix') {262 if (options.scheme) {263 uri = options.scheme + ':' + uri264 } else {265 uri = '//' + uri266 }267 }268 269 // A literal backslash (U+005C) is not a valid RFC 3986 URI character and is270 // not an authority delimiter. Reject it in the authority rather than271 // rewriting it: normalizing "\" -> "/" (WHATWG error recovery) could silently272 // change the resource identified by an otherwise-invalid input, and lets "\"273 // act as a host delimiter here while Node's native URL parses a different274 // host (SSRF / redirect / origin-allowlist bypass). Percent-encoded %5C is275 // untouched and remains valid encoded data.276 const authorityMatch = uri.match(AUTHORITY_PREFIX)277 if (authorityMatch !== null && authorityMatch[1].indexOf('\\') !== -1) {278 parsed.error = 'URI authority must not contain a literal backslash.'279 malformedAuthorityOrPort = true280 }281 282 // Reject a malformed or whitespace-smuggled authority introducer. fast-uri283 // only recognizes a literal "//"; anything else in the leading separator run284 // (a backslash, or a "//" that appears only after removing the TAB/LF/CR that285 // Node strips) means the authority fast-uri parses differs from the one Node's286 // URL resolves. Reject rather than rewrite, mirroring the literal-backslash287 // guard above. Percent-encoded forms (%5C, %09) are untouched, valid data.288 const introducerMatch = uri.match(AUTHORITY_INTRODUCER_REGION)289 if (introducerMatch !== null) {290 const region = introducerMatch[1]291 const normalizedRegion = region.replace(/[\t\n\r]/g, '')292 // Two or more leading separators introduce an authority.293 if (normalizedRegion.length >= 2) {294 if (normalizedRegion.slice(0, 2) !== '//') {295 parsed.error = parsed.error || 'URI authority must not contain a literal backslash.'296 malformedAuthorityOrPort = true297 } else if (region.length !== normalizedRegion.length) {298 parsed.error = parsed.error || 'URI authority introducer must not contain whitespace.'299 malformedAuthorityOrPort = true300 }301 }302 }303 304 const matches = uri.match(URI_PARSE)305 306 if (matches) {307 // store each component308 parsed.scheme = matches[1]309 parsed.userinfo = matches[3]310 parsed.host = matches[4]311 parsed.port = parseInt(matches[5], 10)312 parsed.path = matches[6] || ''313 parsed.query = matches[7]314 parsed.fragment = matches[8]315 316 // fix port number317 if (isNaN(parsed.port)) {318 parsed.port = matches[5]319 }320 321 const parseError = getParseError(parsed, matches)322 if (parseError !== undefined) {323 parsed.error = parsed.error || parseError324 malformedAuthorityOrPort = true325 }326 327 if (parsed.host) {328 const ipv4result = isIPv4(parsed.host)329 if (ipv4result === false) {330 const ipv6result = normalizeIPv6(parsed.host)331 parsed.host = ipv6result.host.toLowerCase()332 isIP = ipv6result.isIPV6333 } else {334 isIP = true335 }336 }337 if (parsed.scheme === undefined && parsed.userinfo === undefined && parsed.host === undefined && parsed.port === undefined && parsed.query === undefined && !parsed.path) {338 parsed.reference = 'same-document'339 } else if (parsed.scheme === undefined) {340 parsed.reference = 'relative'341 } else if (parsed.fragment === undefined) {342 parsed.reference = 'absolute'343 } else {344 parsed.reference = 'uri'345 }346 347 // check for reference errors348 if (options.reference && options.reference !== 'suffix' && options.reference !== parsed.reference) {349 parsed.error = parsed.error || 'URI is not a ' + options.reference + ' reference.'350 }351 352 // find scheme handler353 const schemeHandler = getSchemeHandler(options.scheme || parsed.scheme)354 355 // check if scheme can't handle IRIs356 if (!options.unicodeSupport && (!schemeHandler || !schemeHandler.unicodeSupport)) {357 // if host component is a domain name358 if (parsed.host && (options.domainHost || (schemeHandler && schemeHandler.domainHost)) && isIP === false && nonSimpleDomain(parsed.host)) {359 // convert Unicode IDN -> ASCII IDN360 try {361 parsed.host = new URL('http://' + parsed.host).hostname362 } catch (e) {363 parsed.error = parsed.error || "Host's domain name can not be converted to ASCII: " + e364 }365 }366 // convert IRI -> URI367 }368 369 if (!schemeHandler || (schemeHandler && !schemeHandler.skipNormalize)) {370 if (uri.indexOf('%') !== -1) {371 if (parsed.scheme !== undefined) {372 parsed.scheme = unescape(parsed.scheme)373 }374 if (parsed.host !== undefined) {375 parsed.host = reescapeHostDelimiters(unescape(parsed.host), isIP)376 }377 }378 if (parsed.path) {379 parsed.path = normalizePathEncoding(parsed.path)380 }381 if (parsed.fragment) {382 try {383 parsed.fragment = encodeURI(decodeURIComponent(parsed.fragment))384 } catch {385 parsed.error = parsed.error || 'URI malformed'386 }387 }388 }389 390 // perform scheme specific parsing391 if (schemeHandler && schemeHandler.parse) {392 schemeHandler.parse(parsed, options)393 }394 } else {395 parsed.error = parsed.error || 'URI can not be parsed.'396 }397 return { parsed, malformedAuthorityOrPort }398}399 400/**401 * @param {string} uri402 * @param {import('./types/index').Options} [opts]403 * @returns404 */405function parse (uri, opts) {406 return parseWithStatus(uri, opts).parsed407}408 409/**410 * @param {string} uri411 * @param {import('./types/index').Options} [opts]412 * @returns {string}413 */414function normalizeString (uri, opts) {415 return normalizeStringWithStatus(uri, opts).normalized416}417 418/**419 * @param {string} uri420 * @param {import('./types/index').Options} [opts]421 * @returns {{ normalized: string, malformedAuthorityOrPort: boolean }}422 */423function normalizeStringWithStatus (uri, opts) {424 const { parsed, malformedAuthorityOrPort } = parseWithStatus(uri, opts)425 return {426 normalized: malformedAuthorityOrPort ? uri : serialize(parsed, opts),427 malformedAuthorityOrPort428 }429}430 431/**432 * @param {import ('./types/index').URIComponent|string} uri433 * @param {import('./types/index').Options} [opts]434 * @returns {string|undefined}435 */436function normalizeComparableURI (uri, opts) {437 if (typeof uri === 'string') {438 const { normalized, malformedAuthorityOrPort } = normalizeStringWithStatus(uri, opts)439 return malformedAuthorityOrPort ? undefined : normalized440 }441 442 if (typeof uri === 'object') {443 return serialize(uri, opts)444 }445}446 447const fastUri = {448 SCHEMES,449 normalize,450 resolve,451 resolveComponent,452 equal,453 serialize,454 parse455}456 457module.exports = fastUri458module.exports.default = fastUri459module.exports.fastUri = fastUri460 