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
1import * as v from 'valibot';2 3/**4 * Supported MCP protocol versions in order of preference (newest first)5 */6const SUPPORTED_VERSIONS = ['2025-06-18', '2025-03-26', '2024-11-05'];7 8/**9 * Latest stable protocol version10 */11export const LATEST_PROTOCOL_VERSION = SUPPORTED_VERSIONS[0];12 13/**14 * Validate MCP protocol version format (YYYY-MM-DD)15 */16export const ProtocolVersionSchema = v.pipe(17 v.string(),18 v.regex(19 /^\d{4}-\d{2}-\d{2}$/,20 'Protocol version must be in YYYY-MM-DD format',21 ),22);23 24/**25 * Validate that the protocol version is supported26 */27export const SupportedProtocolVersionSchema = v.pipe(28 ProtocolVersionSchema,29 v.check(30 (version) => SUPPORTED_VERSIONS.includes(version),31 'Unsupported protocol version',32 ),33);34 35/**36 * Check if a protocol version is supported37 * @param {string} version - The protocol version to check38 * @returns {boolean} True if the version is supported39 */40export function is_supported_version(version) {41 return SUPPORTED_VERSIONS.includes(version);42}43 44/**45 * Get the latest supported protocol version46 * @returns {string} The latest protocol version47 */48export function get_latest_version() {49 return LATEST_PROTOCOL_VERSION;50}51 52/**53 * Get all supported protocol versions54 * @returns {string[]} Array of supported protocol versions55 */56export function get_supported_versions() {57 return [...SUPPORTED_VERSIONS];58}59 60/**61 * Compare two protocol versions62 * @param {string} version1 - First version to compare63 * @param {string} version2 - Second version to compare64 * @returns {number} -1 if version1 < version2, 0 if equal, 1 if version1 > version265 */66export function compare_versions(version1, version2) {67 // Parse versions as dates for comparison68 const date1 = new Date(version1);69 const date2 = new Date(version2);70 71 if (date1 < date2) return -1;72 if (date1 > date2) return 1;73 return 0;74}75 76/**77 * Check if a protocol version is newer than another78 * @param {string} version1 - Version to check79 * @param {string} version2 - Version to compare against80 * @returns {boolean} True if version1 is newer than version281 */82export function is_newer_version(version1, version2) {83 return compare_versions(version1, version2) > 0;84}85 86/**87 * Check if a protocol version is older than another88 * @param {string} version1 - Version to check89 * @param {string} version2 - Version to compare against90 * @returns {boolean} True if version1 is older than version291 */92export function is_older_version(version1, version2) {93 return compare_versions(version1, version2) < 0;94}95 96const feature_versions = {97 // 2025-06-18 features98 'elicitation/create': '2025-06-18',99 structured_tool_output: '2025-06-18',100 resource_links: '2025-06-18',101 oauth_resource_indicators: '2025-06-18',102 no_batching: '2025-06-18',103 protocol_version_headers: '2025-06-18',104 105 // 2025-03-26 features106 authorization: '2025-03-26',107 108 // 2024-11-05 features (initial MCP release)109 'sampling/createMessage': '2024-11-05',110 'roots/list': '2024-11-05',111 'notifications/roots/list_changed': '2024-11-05',112 'tools/list': '2024-11-05',113 'tools/call': '2024-11-05',114 'notifications/tools/list_changed': '2024-11-05',115 'resources/list': '2024-11-05',116 'resources/read': '2024-11-05',117 'resources/subscribe': '2024-11-05',118 'resources/templates/list': '2024-11-05',119 'notifications/resources/list_changed': '2024-11-05',120 'notifications/resources/updated': '2024-11-05',121 'prompts/list': '2024-11-05',122 'prompts/get': '2024-11-05',123 'notifications/prompts/list_changed': '2024-11-05',124 'completion/complete': '2024-11-05',125 initialize: '2024-11-05',126 ping: '2024-11-05',127 'notifications/initialized': '2024-11-05',128};129 130/**131 * Get the minimum version required for a feature132 * @param {string} feature - The feature name133 * @returns {string|null} The minimum version required, or null if unknown134 */135export function get_minimum_version_for_feature(feature) {136 return feature_versions[/** @type {never} */ (feature)] || null;137}138 139/**140 * Check if a feature is supported in a given protocol version141 * @param {string} feature - The feature name142 * @param {string} version - The protocol version to check143 * @returns {boolean} True if the feature is supported144 */145export function is_feature_supported(feature, version) {146 const min_version = get_minimum_version_for_feature(feature);147 if (!min_version) return false;148 149 return compare_versions(version, min_version) >= 0;150}151 152/**153 * Create a protocol version validation error154 * @param {string} version - The invalid version155 * @param {string} reason - The reason for the error156 * @returns {Error} The validation error157 */158export function create_version_error(version, reason) {159 return new Error(160 `Protocol version validation failed: ${reason}. Received: ${version}, Supported: ${SUPPORTED_VERSIONS.join(', ')}`,161 );162}163 164/**165 * Negotiate protocol version between client and server166 * According to MCP spec:167 * - If server supports client's version, return same version168 * - Otherwise, return server's latest supported version169 * @param {string} client_version - The protocol version requested by client170 * @returns {string} The negotiated protocol version171 */172export function negotiate_protocol_version(client_version) {173 // If server supports the client's version, use it174 if (is_supported_version(client_version)) {175 return client_version;176 }177 178 // Otherwise, return server's latest supported version179 return get_latest_version();180}181 182/**183 * Check if version negotiation should result in an error184 * @param {string} client_version - The protocol version requested by client185 * @returns {boolean} True if negotiation should fail186 */187export function should_version_negotiation_fail(client_version) {188 // Only fail if the client version format is completely invalid189 try {190 // Test basic format validation191 const date = new Date(client_version);192 const regex = /^\d{4}-\d{2}-\d{2}$/;193 return !regex.test(client_version) || isNaN(date.getTime());194 } catch {195 return true;196 }197}198 