/** * 区分"请求体是旧的"还是"响应是旧的":两次请求用不同的工具名。 * 用法: node scripts/probe-mix.mjs [base] */ import http from 'node:http'; const BASE = process.argv[2] || 'http://127.0.0.1:5399'; const url = new URL(BASE); const agent = new http.Agent({ keepAlive: true, maxSockets: 1 }); function call(payload) { return new Promise((resolve) => { const data = JSON.stringify(payload); const req = http.request( { hostname: url.hostname, port: url.port, path: '/api/tools/run', method: 'POST', agent, headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(data) }, }, (res) => { let out = ''; res.on('data', (c) => (out += c)); res.on('end', () => resolve(out.replace(/\s+/g, ' ').slice(0, 150))); }, ); req.end(data); }); } console.log('#1 shell echo A →', await call({ name: 'shell', args: { command: 'echo A' } })); console.log('#2 calc 1+1 →', await call({ name: 'calc', args: { expression: '1+1' } })); console.log('#3 shell echo C →', await call({ name: 'shell', args: { command: 'echo C' } })); console.log('#4 calc 9*9 →', await call({ name: 'calc', args: { expression: '9*9' } })); console.log('#5 now →', await call({ name: 'now', args: {} })); agent.destroy();