squeezr-ai 1.11.2 → 1.11.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +25 -1
- package/dist/server.js +14 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import tls from 'node:tls';
|
|
1
2
|
import { serve } from '@hono/node-server';
|
|
2
3
|
import { app, stats } from './server.js';
|
|
3
4
|
import { config } from './config.js';
|
|
4
5
|
import { VERSION } from './version.js';
|
|
5
6
|
const PORT = config.port;
|
|
6
|
-
serve({ fetch: app.fetch, port: PORT }, () => {
|
|
7
|
+
const server = serve({ fetch: app.fetch, port: PORT }, () => {
|
|
7
8
|
console.log(`Squeezr v${VERSION} listening on http://localhost:${PORT}`);
|
|
8
9
|
console.log(`Mode: ${config.dryRun ? 'dry-run' : 'active'}`);
|
|
9
10
|
if (config.disabled)
|
|
@@ -11,6 +12,29 @@ serve({ fetch: app.fetch, port: PORT }, () => {
|
|
|
11
12
|
console.log(`Backends: Anthropic → Haiku | OpenAI → GPT-4o-mini | Gemini → Flash-8B | Local → ${config.localCompressionModel}`);
|
|
12
13
|
console.log(`Stats: http://localhost:${PORT}/squeezr/stats`);
|
|
13
14
|
});
|
|
15
|
+
server.on('upgrade', (req, socket, head) => {
|
|
16
|
+
if (req.url !== '/responses') {
|
|
17
|
+
socket.destroy();
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const targetHost = 'api.openai.com';
|
|
21
|
+
const targetPath = '/v1/responses';
|
|
22
|
+
const upstream = tls.connect({ host: targetHost, port: 443, servername: targetHost }, () => {
|
|
23
|
+
// Rebuild the HTTP upgrade request with the correct host and path
|
|
24
|
+
const fwdHeaders = Object.entries(req.headers)
|
|
25
|
+
.filter(([k]) => k.toLowerCase() !== 'host')
|
|
26
|
+
.map(([k, v]) => `${k}: ${v}`)
|
|
27
|
+
.join('\r\n');
|
|
28
|
+
const upgradeReq = `GET ${targetPath} HTTP/1.1\r\nHost: ${targetHost}\r\n${fwdHeaders}\r\n\r\n`;
|
|
29
|
+
upstream.write(upgradeReq);
|
|
30
|
+
if (head.length > 0)
|
|
31
|
+
upstream.write(head);
|
|
32
|
+
upstream.pipe(socket);
|
|
33
|
+
socket.pipe(upstream);
|
|
34
|
+
});
|
|
35
|
+
upstream.on('error', () => socket.destroy());
|
|
36
|
+
socket.on('error', () => upstream.destroy());
|
|
37
|
+
});
|
|
14
38
|
const isDaemon = !!process.env.SQUEEZR_DAEMON;
|
|
15
39
|
if (isDaemon) {
|
|
16
40
|
// Daemon mode: ignore SIGINT (Ctrl+C) and SIGHUP (terminal close)
|
package/dist/server.js
CHANGED
|
@@ -236,8 +236,20 @@ app.get('/squeezr/expand/:id', (c) => {
|
|
|
236
236
|
app.all('*', async (c) => {
|
|
237
237
|
const upstream = detectUpstream(c.req.raw.headers);
|
|
238
238
|
const url = new URL(c.req.url);
|
|
239
|
-
const
|
|
240
|
-
|
|
239
|
+
const auth = extractOpenAIKey(c.req.raw.headers);
|
|
240
|
+
let targetPath = url.pathname;
|
|
241
|
+
let finalUpstream = upstream;
|
|
242
|
+
if (url.pathname === '/responses') {
|
|
243
|
+
const isOAuth = auth && !auth.startsWith('sk-');
|
|
244
|
+
if (isOAuth) {
|
|
245
|
+
finalUpstream = 'https://chatgpt.com/backend-api';
|
|
246
|
+
targetPath = '/responses';
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
targetPath = '/v1/responses';
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
const targetUrl = `${finalUpstream}${targetPath}${url.search}`;
|
|
241
253
|
const body = await c.req.arrayBuffer();
|
|
242
254
|
const fwdHeaders = forwardHeaders(c.req.raw.headers);
|
|
243
255
|
const resp = await fetch(targetUrl, {
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "1.11.
|
|
1
|
+
export declare const VERSION = "1.11.3";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '1.11.
|
|
1
|
+
export const VERSION = '1.11.3';
|
package/package.json
CHANGED