From 635d327dbc6fb45fb2a09adc310f02f661837b33 Mon Sep 17 00:00:00 2001 From: decolua Date: Mon, 9 Feb 2026 00:15:31 +0700 Subject: [PATCH] chore: update package version to 0.2.71 and enhance MITM tools --- open-sse/translator/helpers/claudeHelper.js | 1 + .../translator/helpers/maxTokensHelper.js | 6 ++- package.json | 2 +- src/mitm/cert/install.js | 4 +- src/mitm/dns/dnsConfig.js | 45 +++++++++++++------ 5 files changed, 41 insertions(+), 17 deletions(-) diff --git a/open-sse/translator/helpers/claudeHelper.js b/open-sse/translator/helpers/claudeHelper.js index 6abc904..9c75cd3 100644 --- a/open-sse/translator/helpers/claudeHelper.js +++ b/open-sse/translator/helpers/claudeHelper.js @@ -1,5 +1,6 @@ // Claude helper functions for translator import { DEFAULT_THINKING_CLAUDE_SIGNATURE } from "../../config/defaultThinkingSignature.js"; +import { adjustMaxTokens } from "./maxTokensHelper.js"; // Check if message has valid non-empty content export function hasValidContent(msg) { diff --git a/open-sse/translator/helpers/maxTokensHelper.js b/open-sse/translator/helpers/maxTokensHelper.js index 57235a0..4627fab 100644 --- a/open-sse/translator/helpers/maxTokensHelper.js +++ b/open-sse/translator/helpers/maxTokensHelper.js @@ -9,13 +9,17 @@ export function adjustMaxTokens(body) { let maxTokens = body.max_tokens || DEFAULT_MAX_TOKENS; // Auto-increase for tool calling to prevent truncated arguments - // Tool calls with large content (like writing files) need more tokens if (body.tools && Array.isArray(body.tools) && body.tools.length > 0) { if (maxTokens < DEFAULT_MIN_TOKENS) { maxTokens = DEFAULT_MIN_TOKENS; } } + // Ensure max_tokens > thinking.budget_tokens (Claude API requirement) + if (body.thinking?.budget_tokens && maxTokens <= body.thinking.budget_tokens) { + maxTokens = DEFAULT_MAX_TOKENS; + } + return maxTokens; } diff --git a/package.json b/package.json index 73b5724..32be6b2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "9router-app", - "version": "0.2.70", + "version": "0.2.72", "description": "9Router web dashboard", "private": true, "scripts": { diff --git a/src/mitm/cert/install.js b/src/mitm/cert/install.js index 644add2..a0d29d4 100644 --- a/src/mitm/cert/install.js +++ b/src/mitm/cert/install.js @@ -66,7 +66,7 @@ async function installCert(sudoPassword, certPath) { } async function installCertMac(sudoPassword, certPath) { - const command = `sudo -S security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain "${certPath}"`; + const command = `security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain "${certPath}"`; try { await execWithPassword(command, sudoPassword); console.log(`✅ Installed certificate to system keychain: ${certPath}`); @@ -110,7 +110,7 @@ async function uninstallCert(sudoPassword, certPath) { async function uninstallCertMac(sudoPassword, certPath) { const fingerprint = getCertFingerprint(certPath).replace(/:/g, ""); - const command = `sudo -S security delete-certificate -Z "${fingerprint}" /Library/Keychains/System.keychain`; + const command = `security delete-certificate -Z "${fingerprint}" /Library/Keychains/System.keychain`; try { await execWithPassword(command, sudoPassword); console.log("✅ Uninstalled certificate from system keychain"); diff --git a/src/mitm/dns/dnsConfig.js b/src/mitm/dns/dnsConfig.js index 2d62944..da76ca0 100644 --- a/src/mitm/dns/dnsConfig.js +++ b/src/mitm/dns/dnsConfig.js @@ -1,4 +1,4 @@ -const { exec } = require("child_process"); +const { exec, spawn } = require("child_process"); const fs = require("fs"); const path = require("path"); @@ -13,13 +13,20 @@ const HOSTS_FILE = IS_WIN */ function execWithPassword(command, password) { return new Promise((resolve, reject) => { - const child = exec(command, (error, stdout, stderr) => { - if (error) { - reject(new Error(`Command failed: ${error.message}\n${stderr}`)); - } else { - resolve(stdout); - } + const child = spawn("sudo", ["-S", "sh", "-c", command], { + stdio: ["pipe", "pipe", "pipe"] }); + + let stdout = ""; + let stderr = ""; + child.stdout.on("data", (d) => { stdout += d; }); + child.stderr.on("data", (d) => { stderr += d; }); + + child.on("close", (code) => { + if (code === 0) resolve(stdout); + else reject(new Error(stderr || `Exit code ${code}`)); + }); + child.stdin.write(`${password}\n`); child.stdin.end(); }); @@ -69,12 +76,18 @@ async function addDNSEntry(sudoPassword) { // Windows: use elevated echo >> hosts await execElevatedWindows(`echo ${entry} >> "${HOSTS_FILE}"`); } else { - const command = `echo "${entry}" | sudo -S tee -a ${HOSTS_FILE} > /dev/null`; - await execWithPassword(command, sudoPassword); + await execWithPassword(`echo "${entry}" >> ${HOSTS_FILE}`, sudoPassword); + } + // Flush DNS cache + if (IS_WIN) { + await execElevatedWindows("ipconfig /flushdns"); + } else { + await execWithPassword("dscacheutil -flushcache && killall -HUP mDNSResponder", sudoPassword); } console.log(`✅ Added DNS entry: ${entry}`); } catch (error) { - throw new Error(`Failed to add DNS entry: ${error.message}`); + const msg = error.message?.includes("incorrect password") ? "Wrong sudo password" : "Failed to add DNS entry"; + throw new Error(msg); } } @@ -99,12 +112,18 @@ async function removeDNSEntry(sudoPassword) { }); }); } else { - const command = `sudo -S sed -i '' '/${TARGET_HOST}/d' ${HOSTS_FILE}`; - await execWithPassword(command, sudoPassword); + await execWithPassword(`sed -i '' '/${TARGET_HOST}/d' ${HOSTS_FILE}`, sudoPassword); + } + // Flush DNS cache + if (IS_WIN) { + await execElevatedWindows("ipconfig /flushdns"); + } else { + await execWithPassword("dscacheutil -flushcache && killall -HUP mDNSResponder", sudoPassword); } console.log(`✅ Removed DNS entry for ${TARGET_HOST}`); } catch (error) { - throw new Error(`Failed to remove DNS entry: ${error.message}`); + const msg = error.message?.includes("incorrect password") ? "Wrong sudo password" : "Failed to remove DNS entry"; + throw new Error(msg); } }