mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-22 20:00:47 +00:00
# v0.4.52 (2026-05-17)
## Features - Add Vercel AI Gateway provider support (#1183) - rtk: Kiro format tool result compression — handle conversationState.history & currentMessage, preserve error results, ~13.6% savings (#1194) ## Fixes - openclaw: normalize agent.model object form `{primary, fallbacks}` before .startsWith → fix TypeError & 'not configured' status (#1216) - Usage Details pagination: stay inside mobile viewport <640px (#1218) - Fix test model error - Fix MIMO provider in Codex - Disable log file creation when using MITM AG
This commit is contained in:
@@ -1,52 +1,40 @@
|
||||
import { machineIdSync } from 'node-machine-id';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import crypto from 'node:crypto';
|
||||
import { DATA_DIR } from '@/lib/dataDir';
|
||||
|
||||
/**
|
||||
* Get consistent machine ID using node-machine-id with salt
|
||||
* This ensures the same physical machine gets the same ID across runs
|
||||
*
|
||||
* @param {string} salt - Optional salt to use (defaults to environment variable)
|
||||
* @returns {Promise<string>} Machine ID (16-character base32)
|
||||
*/
|
||||
export async function getConsistentMachineId(salt = null) {
|
||||
// For server-side, use node-machine-id with salt
|
||||
const saltValue = salt || process.env.MACHINE_ID_SALT || 'endpoint-proxy-salt';
|
||||
const MACHINE_ID_FILE = path.join(DATA_DIR, 'machine-id');
|
||||
let cachedRawId = null;
|
||||
|
||||
// Persist raw machine ID to file → guarantees CLI/server/middleware see same value
|
||||
// even when machineIdSync fails or returns inconsistent values across runtimes.
|
||||
function loadRawMachineId() {
|
||||
if (cachedRawId) return cachedRawId;
|
||||
try {
|
||||
const rawMachineId = machineIdSync();
|
||||
// Create consistent ID using salt
|
||||
const crypto = await import('crypto');
|
||||
const hashedMachineId = crypto.createHash('sha256').update(rawMachineId + saltValue).digest('hex');
|
||||
// Return only first 16 characters for brevity
|
||||
return hashedMachineId.substring(0, 16);
|
||||
} catch (error) {
|
||||
console.log('Error getting machine ID:', error);
|
||||
// Fallback to random ID if node-machine-id fails
|
||||
return crypto.randomUUID ? crypto.randomUUID() :
|
||||
'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
||||
const r = Math.random() * 16 | 0;
|
||||
const v = c == 'x' ? r : (r & 0x3 | 0x8);
|
||||
return v.toString(16);
|
||||
});
|
||||
cachedRawId = fs.readFileSync(MACHINE_ID_FILE, 'utf8').trim();
|
||||
if (cachedRawId) return cachedRawId;
|
||||
} catch {}
|
||||
try {
|
||||
cachedRawId = machineIdSync();
|
||||
} catch {
|
||||
cachedRawId = crypto.randomUUID();
|
||||
}
|
||||
try {
|
||||
fs.mkdirSync(DATA_DIR, { recursive: true });
|
||||
fs.writeFileSync(MACHINE_ID_FILE, cachedRawId, { mode: 0o600 });
|
||||
} catch {}
|
||||
return cachedRawId;
|
||||
}
|
||||
|
||||
export async function getConsistentMachineId(salt = null) {
|
||||
const saltValue = salt || process.env.MACHINE_ID_SALT || 'endpoint-proxy-salt';
|
||||
const raw = loadRawMachineId();
|
||||
return crypto.createHash('sha256').update(raw + saltValue).digest('hex').substring(0, 16);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get raw machine ID without hashing (for debugging purposes)
|
||||
* @returns {Promise<string>} Raw machine ID
|
||||
*/
|
||||
export async function getRawMachineId() {
|
||||
// For server-side, use raw node-machine-id
|
||||
try {
|
||||
return machineIdSync();
|
||||
} catch (error) {
|
||||
console.log('Error getting raw machine ID:', error);
|
||||
// Fallback to random ID if node-machine-id fails
|
||||
return crypto.randomUUID ? crypto.randomUUID() :
|
||||
'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
||||
const r = Math.random() * 16 | 0;
|
||||
const v = c == 'x' ? r : (r & 0x3 | 0x8);
|
||||
return v.toString(16);
|
||||
});
|
||||
}
|
||||
return loadRawMachineId();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user