| 11 | const { buildMessagesHandler } = require('../src/proxy/router/messages_route'); |
| 12 | |
| 13 | function rawPost(url, token, body) { |
| 14 | return new Promise((resolve, reject) => { |
| 15 | const u = new URL(url); |
| 16 | const payload = JSON.stringify(body || {}); |
| 17 | const req = http.request({ |
| 18 | hostname: u.hostname, |
| 19 | port: u.port, |
| 20 | path: u.pathname, |
| 21 | method: 'POST', |
| 22 | headers: { |
| 23 | 'Authorization': 'Bearer ' + token, |
| 24 | 'Content-Type': 'application/json', |
| 25 | 'Content-Length': Buffer.byteLength(payload), |
| 26 | 'x-api-key': 'sk-test', |
| 27 | 'anthropic-version': '2023-06-01', |
| 28 | }, |
| 29 | }, (res) => { |
| 30 | const chunks = []; |
| 31 | res.on('data', (c) => chunks.push(c)); |
| 32 | res.on('end', () => resolve({ |
| 33 | status: res.statusCode, |
| 34 | headers: res.headers, |
| 35 | body: Buffer.concat(chunks).toString(), |
| 36 | })); |
| 37 | }); |
| 38 | req.on('error', reject); |
| 39 | req.write(payload); |
| 40 | req.end(); |
| 41 | }); |
| 42 | } |
| 43 | |
| 44 | function startStubAnthropic(handler) { |
| 45 | return new Promise((resolve) => { |