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";2var __create = Object.create;3var __defProp = Object.defineProperty;4var __getOwnPropDesc = Object.getOwnPropertyDescriptor;5var __getOwnPropNames = Object.getOwnPropertyNames;6var __getProtoOf = Object.getPrototypeOf;7var __hasOwnProp = Object.prototype.hasOwnProperty;8var __export = (target, all) => {9 for (var name in all)10 __defProp(target, name, { get: all[name], enumerable: true });11};12var __copyProps = (to, from, except, desc) => {13 if (from && typeof from === "object" || typeof from === "function") {14 for (let key of __getOwnPropNames(from))15 if (!__hasOwnProp.call(to, key) && key !== except)16 __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });17 }18 return to;19};20var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(21 // If the importer is in node compatibility mode or this is not an ESM22 // file that has been converted to a CommonJS file using a Babel-23 // compatible transform (i.e. "__esModule" has not been set), then set24 // "default" to the CommonJS "module.exports" for node compatibility.25 isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,26 mod27));28var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);29var socksClientCertificatesInterceptor_exports = {};30__export(socksClientCertificatesInterceptor_exports, {31 ClientCertificatesProxy: () => ClientCertificatesProxy,32 getMatchingTLSOptionsForOrigin: () => getMatchingTLSOptionsForOrigin,33 rewriteOpenSSLErrorIfNeeded: () => rewriteOpenSSLErrorIfNeeded34});35module.exports = __toCommonJS(socksClientCertificatesInterceptor_exports);36var import_events = require("events");37var import_http2 = __toESM(require("http2"));38var import_net = __toESM(require("net"));39var import_stream = __toESM(require("stream"));40var import_tls = __toESM(require("tls"));41var import_socksProxy = require("./utils/socksProxy");42var import_utils = require("../utils");43var import_browserContext = require("./browserContext");44var import_network = require("./utils/network");45var import_debugLogger = require("./utils/debugLogger");46var import_happyEyeballs = require("./utils/happyEyeballs");47var import_utilsBundle = require("../utilsBundle");48let dummyServerTlsOptions = void 0;49function loadDummyServerCertsIfNeeded() {50 if (dummyServerTlsOptions)51 return;52 const { cert, key } = (0, import_utils.generateSelfSignedCertificate)();53 dummyServerTlsOptions = { key, cert };54}55class SocksProxyConnection {56 constructor(socksProxy, uid, host, port) {57 this._firstPackageReceived = false;58 this._closed = false;59 this.socksProxy = socksProxy;60 this.uid = uid;61 this.host = host;62 this.port = port;63 this._serverCloseEventListener = () => {64 this._browserEncrypted.destroy();65 };66 this._browserEncrypted = new import_stream.default.Duplex({67 read: () => {68 },69 write: (data, encoding, callback) => {70 this.socksProxy._socksProxy.sendSocketData({ uid: this.uid, data });71 callback();72 },73 destroy: (error, callback) => {74 if (error)75 socksProxy._socksProxy.sendSocketError({ uid: this.uid, error: error.message });76 else77 socksProxy._socksProxy.sendSocketEnd({ uid: this.uid });78 callback();79 }80 });81 }82 async connect() {83 const proxyAgent = this.socksProxy.getProxyAgent(this.host, this.port);84 if (proxyAgent)85 this._serverEncrypted = await proxyAgent.callback(new import_events.EventEmitter(), { host: rewriteToLocalhostIfNeeded(this.host), port: this.port, secureEndpoint: false });86 else87 this._serverEncrypted = await (0, import_happyEyeballs.createSocket)(rewriteToLocalhostIfNeeded(this.host), this.port);88 this._serverEncrypted.once("close", this._serverCloseEventListener);89 this._serverEncrypted.once("error", (error) => this._browserEncrypted.destroy(error));90 if (this._closed) {91 this._serverEncrypted.destroy();92 return;93 }94 this.socksProxy._socksProxy.socketConnected({95 uid: this.uid,96 host: this._serverEncrypted.localAddress,97 port: this._serverEncrypted.localPort98 });99 }100 onClose() {101 this._serverEncrypted.destroy();102 this._browserEncrypted.destroy();103 this._closed = true;104 }105 onData(data) {106 if (!this._firstPackageReceived) {107 this._firstPackageReceived = true;108 if (data[0] === 22)109 this._establishTlsTunnel(this._browserEncrypted, data);110 else111 this._establishPlaintextTunnel(this._browserEncrypted);112 }113 this._browserEncrypted.push(data);114 }115 _establishPlaintextTunnel(browserEncrypted) {116 browserEncrypted.pipe(this._serverEncrypted);117 this._serverEncrypted.pipe(browserEncrypted);118 }119 _establishTlsTunnel(browserEncrypted, clientHello) {120 const browserALPNProtocols = parseALPNFromClientHello(clientHello) || ["http/1.1"];121 import_debugLogger.debugLogger.log("client-certificates", `Browser->Proxy ${this.host}:${this.port} offers ALPN ${browserALPNProtocols}`);122 const serverDecrypted = import_tls.default.connect({123 socket: this._serverEncrypted,124 host: this.host,125 port: this.port,126 rejectUnauthorized: !this.socksProxy.ignoreHTTPSErrors,127 ALPNProtocols: browserALPNProtocols,128 servername: !import_net.default.isIP(this.host) ? this.host : void 0,129 secureContext: this.socksProxy.secureContextMap.get(new URL(`https://${this.host}:${this.port}`).origin)130 }, async () => {131 const browserDecrypted = await this._upgradeToTLSIfNeeded(browserEncrypted, serverDecrypted.alpnProtocol);132 import_debugLogger.debugLogger.log("client-certificates", `Proxy->Server ${this.host}:${this.port} chooses ALPN ${browserDecrypted.alpnProtocol}`);133 browserDecrypted.pipe(serverDecrypted);134 serverDecrypted.pipe(browserDecrypted);135 const cleanup = (error) => this._serverEncrypted.destroy(error);136 browserDecrypted.once("error", cleanup);137 serverDecrypted.once("error", cleanup);138 browserDecrypted.once("close", cleanup);139 serverDecrypted.once("close", cleanup);140 if (this._closed)141 serverDecrypted.destroy();142 });143 serverDecrypted.once("error", async (error) => {144 import_debugLogger.debugLogger.log("client-certificates", `error when connecting to server: ${error.message.replaceAll("\n", " ")}`);145 this._serverEncrypted.removeListener("close", this._serverCloseEventListener);146 this._serverEncrypted.destroy();147 const browserDecrypted = await this._upgradeToTLSIfNeeded(this._browserEncrypted, serverDecrypted.alpnProtocol);148 const responseBody = (0, import_utils.escapeHTML)("Playwright client-certificate error: " + error.message).replaceAll("\n", " <br>");149 if (browserDecrypted.alpnProtocol === "h2") {150 if ("performServerHandshake" in import_http2.default) {151 const session = import_http2.default.performServerHandshake(browserDecrypted);152 session.on("error", (error2) => {153 this._browserEncrypted.destroy(error2);154 });155 session.once("stream", (stream2) => {156 const cleanup = (error2) => {157 session.close();158 this._browserEncrypted.destroy(error2);159 };160 stream2.once("end", cleanup);161 stream2.once("error", cleanup);162 stream2.respond({163 [import_http2.default.constants.HTTP2_HEADER_CONTENT_TYPE]: "text/html",164 [import_http2.default.constants.HTTP2_HEADER_STATUS]: 503165 });166 stream2.end(responseBody);167 });168 } else {169 this._browserEncrypted.destroy(error);170 }171 } else {172 browserDecrypted.end([173 "HTTP/1.1 503 Internal Server Error",174 "Content-Type: text/html; charset=utf-8",175 "Content-Length: " + Buffer.byteLength(responseBody),176 "",177 responseBody178 ].join("\r\n"));179 }180 });181 }182 async _upgradeToTLSIfNeeded(socket, alpnProtocol) {183 this._brorwserDecrypted ??= new Promise((resolve, reject) => {184 const dummyServer = import_tls.default.createServer({185 ...dummyServerTlsOptions,186 ALPNProtocols: [alpnProtocol || "http/1.1"]187 });188 dummyServer.emit("connection", socket);189 dummyServer.once("secureConnection", (tlsSocket) => {190 dummyServer.close();191 resolve(tlsSocket);192 });193 dummyServer.once("error", (error) => {194 dummyServer.close();195 reject(error);196 });197 });198 return this._brorwserDecrypted;199 }200}201class ClientCertificatesProxy {202 constructor(contextOptions) {203 this._connections = /* @__PURE__ */ new Map();204 this.secureContextMap = /* @__PURE__ */ new Map();205 (0, import_browserContext.verifyClientCertificates)(contextOptions.clientCertificates);206 this.ignoreHTTPSErrors = contextOptions.ignoreHTTPSErrors;207 this._proxy = contextOptions.proxy;208 this._initSecureContexts(contextOptions.clientCertificates);209 this._socksProxy = new import_socksProxy.SocksProxy();210 this._socksProxy.setPattern("*");211 this._socksProxy.addListener(import_socksProxy.SocksProxy.Events.SocksRequested, async (payload) => {212 try {213 const connection = new SocksProxyConnection(this, payload.uid, payload.host, payload.port);214 await connection.connect();215 this._connections.set(payload.uid, connection);216 } catch (error) {217 import_debugLogger.debugLogger.log("client-certificates", `Failed to connect to ${payload.host}:${payload.port}: ${error.message}`);218 this._socksProxy.socketFailed({ uid: payload.uid, errorCode: error.code });219 }220 });221 this._socksProxy.addListener(import_socksProxy.SocksProxy.Events.SocksData, (payload) => {222 this._connections.get(payload.uid)?.onData(payload.data);223 });224 this._socksProxy.addListener(import_socksProxy.SocksProxy.Events.SocksClosed, (payload) => {225 this._connections.get(payload.uid)?.onClose();226 this._connections.delete(payload.uid);227 });228 loadDummyServerCertsIfNeeded();229 }230 getProxyAgent(host, port) {231 const proxyFromOptions = (0, import_network.createProxyAgent)(this._proxy);232 if (proxyFromOptions)233 return proxyFromOptions;234 const proxyFromEnv = (0, import_utilsBundle.getProxyForUrl)(`https://${host}:${port}`);235 if (proxyFromEnv)236 return (0, import_network.createProxyAgent)({ server: proxyFromEnv });237 }238 _initSecureContexts(clientCertificates) {239 const origin2certs = /* @__PURE__ */ new Map();240 for (const cert of clientCertificates || []) {241 const origin = normalizeOrigin(cert.origin);242 const certs = origin2certs.get(origin) || [];243 certs.push(cert);244 origin2certs.set(origin, certs);245 }246 for (const [origin, certs] of origin2certs) {247 try {248 this.secureContextMap.set(origin, import_tls.default.createSecureContext(convertClientCertificatesToTLSOptions(certs)));249 } catch (error) {250 error = rewriteOpenSSLErrorIfNeeded(error);251 throw (0, import_utils.rewriteErrorMessage)(error, `Failed to load client certificate: ${error.message}`);252 }253 }254 }255 static async create(progress, contextOptions) {256 const proxy = new ClientCertificatesProxy(contextOptions);257 try {258 await progress.race(proxy._socksProxy.listen(0, "127.0.0.1"));259 return proxy;260 } catch (error) {261 await proxy.close();262 throw error;263 }264 }265 proxySettings() {266 return { server: `socks5://127.0.0.1:${this._socksProxy.port()}` };267 }268 async close() {269 await this._socksProxy.close();270 }271}272function normalizeOrigin(origin) {273 try {274 return new URL(origin).origin;275 } catch (error) {276 return origin;277 }278}279function convertClientCertificatesToTLSOptions(clientCertificates) {280 if (!clientCertificates || !clientCertificates.length)281 return;282 const tlsOptions = {283 pfx: [],284 key: [],285 cert: []286 };287 for (const cert of clientCertificates) {288 if (cert.cert)289 tlsOptions.cert.push(cert.cert);290 if (cert.key)291 tlsOptions.key.push({ pem: cert.key, passphrase: cert.passphrase });292 if (cert.pfx)293 tlsOptions.pfx.push({ buf: cert.pfx, passphrase: cert.passphrase });294 }295 return tlsOptions;296}297function getMatchingTLSOptionsForOrigin(clientCertificates, origin) {298 const matchingCerts = clientCertificates?.filter(299 (c) => normalizeOrigin(c.origin) === origin300 );301 return convertClientCertificatesToTLSOptions(matchingCerts);302}303function rewriteToLocalhostIfNeeded(host) {304 return host === "local.playwright" ? "localhost" : host;305}306function rewriteOpenSSLErrorIfNeeded(error) {307 if (error.message !== "unsupported" && error.code !== "ERR_CRYPTO_UNSUPPORTED_OPERATION")308 return error;309 return (0, import_utils.rewriteErrorMessage)(error, [310 "Unsupported TLS certificate.",311 "Most likely, the security algorithm of the given certificate was deprecated by OpenSSL.",312 "For more details, see https://github.com/openssl/openssl/blob/master/README-PROVIDERS.md#the-legacy-provider",313 "You could probably modernize the certificate by following the steps at https://github.com/nodejs/node/issues/40672#issuecomment-1243648223"314 ].join("\n"));315}316function parseALPNFromClientHello(buffer) {317 if (buffer.length < 6)318 return null;319 if (buffer[0] !== 22)320 return null;321 let offset = 5;322 if (buffer[offset] !== 1)323 return null;324 offset += 4;325 offset += 2;326 offset += 32;327 if (offset >= buffer.length)328 return null;329 const sessionIdLength = buffer[offset];330 offset += 1 + sessionIdLength;331 if (offset + 2 > buffer.length)332 return null;333 const cipherSuitesLength = buffer.readUInt16BE(offset);334 offset += 2 + cipherSuitesLength;335 if (offset >= buffer.length)336 return null;337 const compressionMethodsLength = buffer[offset];338 offset += 1 + compressionMethodsLength;339 if (offset + 2 > buffer.length)340 return null;341 const extensionsLength = buffer.readUInt16BE(offset);342 offset += 2;343 const extensionsEnd = offset + extensionsLength;344 if (extensionsEnd > buffer.length)345 return null;346 while (offset + 4 <= extensionsEnd) {347 const extensionType = buffer.readUInt16BE(offset);348 offset += 2;349 const extensionLength = buffer.readUInt16BE(offset);350 offset += 2;351 if (offset + extensionLength > extensionsEnd)352 return null;353 if (extensionType === 16)354 return parseALPNExtension(buffer.subarray(offset, offset + extensionLength));355 offset += extensionLength;356 }357 return null;358}359function parseALPNExtension(buffer) {360 if (buffer.length < 2)361 return null;362 const listLength = buffer.readUInt16BE(0);363 if (listLength !== buffer.length - 2)364 return null;365 const protocols = [];366 let offset = 2;367 while (offset < buffer.length) {368 const protocolLength = buffer[offset];369 offset += 1;370 if (offset + protocolLength > buffer.length)371 break;372 const protocol = buffer.subarray(offset, offset + protocolLength).toString("utf8");373 protocols.push(protocol);374 offset += protocolLength;375 }376 return protocols.length > 0 ? protocols : null;377}378// Annotate the CommonJS export names for ESM import in node:3790 && (module.exports = {380 ClientCertificatesProxy,381 getMatchingTLSOptionsForOrigin,382 rewriteOpenSSLErrorIfNeeded383});384 