chore: update package version to 0.2.71 and enhance MITM tools

This commit is contained in:
decolua
2026-02-09 00:15:31 +07:00
parent bd0cebcfff
commit 635d327dbc
5 changed files with 41 additions and 17 deletions

View File

@@ -1,5 +1,6 @@
// Claude helper functions for translator // Claude helper functions for translator
import { DEFAULT_THINKING_CLAUDE_SIGNATURE } from "../../config/defaultThinkingSignature.js"; import { DEFAULT_THINKING_CLAUDE_SIGNATURE } from "../../config/defaultThinkingSignature.js";
import { adjustMaxTokens } from "./maxTokensHelper.js";
// Check if message has valid non-empty content // Check if message has valid non-empty content
export function hasValidContent(msg) { export function hasValidContent(msg) {

View File

@@ -9,13 +9,17 @@ export function adjustMaxTokens(body) {
let maxTokens = body.max_tokens || DEFAULT_MAX_TOKENS; let maxTokens = body.max_tokens || DEFAULT_MAX_TOKENS;
// Auto-increase for tool calling to prevent truncated arguments // 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 (body.tools && Array.isArray(body.tools) && body.tools.length > 0) {
if (maxTokens < DEFAULT_MIN_TOKENS) { if (maxTokens < DEFAULT_MIN_TOKENS) {
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; return maxTokens;
} }

View File

@@ -1,6 +1,6 @@
{ {
"name": "9router-app", "name": "9router-app",
"version": "0.2.70", "version": "0.2.72",
"description": "9Router web dashboard", "description": "9Router web dashboard",
"private": true, "private": true,
"scripts": { "scripts": {

View File

@@ -66,7 +66,7 @@ async function installCert(sudoPassword, certPath) {
} }
async function installCertMac(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 { try {
await execWithPassword(command, sudoPassword); await execWithPassword(command, sudoPassword);
console.log(`✅ Installed certificate to system keychain: ${certPath}`); console.log(`✅ Installed certificate to system keychain: ${certPath}`);
@@ -110,7 +110,7 @@ async function uninstallCert(sudoPassword, certPath) {
async function uninstallCertMac(sudoPassword, certPath) { async function uninstallCertMac(sudoPassword, certPath) {
const fingerprint = getCertFingerprint(certPath).replace(/:/g, ""); 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 { try {
await execWithPassword(command, sudoPassword); await execWithPassword(command, sudoPassword);
console.log("✅ Uninstalled certificate from system keychain"); console.log("✅ Uninstalled certificate from system keychain");

View File

@@ -1,4 +1,4 @@
const { exec } = require("child_process"); const { exec, spawn } = require("child_process");
const fs = require("fs"); const fs = require("fs");
const path = require("path"); const path = require("path");
@@ -13,13 +13,20 @@ const HOSTS_FILE = IS_WIN
*/ */
function execWithPassword(command, password) { function execWithPassword(command, password) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const child = exec(command, (error, stdout, stderr) => { const child = spawn("sudo", ["-S", "sh", "-c", command], {
if (error) { stdio: ["pipe", "pipe", "pipe"]
reject(new Error(`Command failed: ${error.message}\n${stderr}`));
} else {
resolve(stdout);
}
}); });
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.write(`${password}\n`);
child.stdin.end(); child.stdin.end();
}); });
@@ -69,12 +76,18 @@ async function addDNSEntry(sudoPassword) {
// Windows: use elevated echo >> hosts // Windows: use elevated echo >> hosts
await execElevatedWindows(`echo ${entry} >> "${HOSTS_FILE}"`); await execElevatedWindows(`echo ${entry} >> "${HOSTS_FILE}"`);
} else { } else {
const command = `echo "${entry}" | sudo -S tee -a ${HOSTS_FILE} > /dev/null`; await execWithPassword(`echo "${entry}" >> ${HOSTS_FILE}`, sudoPassword);
await execWithPassword(command, 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}`); console.log(`✅ Added DNS entry: ${entry}`);
} catch (error) { } 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 { } else {
const command = `sudo -S sed -i '' '/${TARGET_HOST}/d' ${HOSTS_FILE}`; await execWithPassword(`sed -i '' '/${TARGET_HOST}/d' ${HOSTS_FILE}`, sudoPassword);
await execWithPassword(command, 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}`); console.log(`✅ Removed DNS entry for ${TARGET_HOST}`);
} catch (error) { } 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);
} }
} }