squeezr-ai 1.14.2 → 1.14.5
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/bin/squeezr.js +2 -1
- package/dist/compressor.js +6 -2
- package/dist/config.js +2 -1
- package/dist/server.js +24 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/bin/squeezr.js
CHANGED
|
@@ -198,8 +198,9 @@ function setupWindows() {
|
|
|
198
198
|
openai_base_url: `http://localhost:${port}`,
|
|
199
199
|
GEMINI_API_BASE_URL: `http://localhost:${port}`,
|
|
200
200
|
HTTPS_PROXY: `http://localhost:${mitmPort}`,
|
|
201
|
-
// Node.js does NOT use the Windows Certificate Store — this makes Codex (Node.js) trust the MITM CA
|
|
202
201
|
NODE_EXTRA_CA_CERTS: caPath,
|
|
202
|
+
// Bypass MITM for OpenAI auth and non-Codex endpoints — only chatgpt.com needs interception
|
|
203
|
+
NO_PROXY: 'auth.openai.com,login.openai.com,api.openai.com,api.anthropic.com,generativelanguage.googleapis.com',
|
|
203
204
|
}
|
|
204
205
|
for (const [key, value] of Object.entries(vars)) {
|
|
205
206
|
try {
|
package/dist/compressor.js
CHANGED
|
@@ -25,7 +25,9 @@ async function compressWithHaiku(text, apiKey) {
|
|
|
25
25
|
// The Anthropic SDK accepts both: apiKey → x-api-key header,
|
|
26
26
|
// authToken → Authorization: Bearer header.
|
|
27
27
|
const authOpts = apiKey.startsWith('sk-') ? { apiKey } : { authToken: apiKey };
|
|
28
|
-
|
|
28
|
+
// Force real API URL — ANTHROPIC_BASE_URL points to this proxy, which would cause
|
|
29
|
+
// infinite recursion if we let the SDK inherit it from the environment.
|
|
30
|
+
const client = new Anthropic({ ...authOpts, baseURL: 'https://api.anthropic.com' });
|
|
29
31
|
const resp = await client.messages.create({
|
|
30
32
|
model: 'claude-haiku-4-5-20251001',
|
|
31
33
|
max_tokens: 300,
|
|
@@ -35,7 +37,9 @@ async function compressWithHaiku(text, apiKey) {
|
|
|
35
37
|
}
|
|
36
38
|
async function compressWithGptMini(text, apiKey) {
|
|
37
39
|
// apiKey can be a real key (sk-...) or an OAuth bearer token
|
|
38
|
-
|
|
40
|
+
// Force real API URL — openai_base_url points to this proxy, which would cause
|
|
41
|
+
// infinite recursion if we let the SDK inherit it from the environment.
|
|
42
|
+
const client = new OpenAI({ apiKey, baseURL: 'https://api.openai.com/v1' });
|
|
39
43
|
const resp = await client.chat.completions.create({
|
|
40
44
|
model: 'gpt-4o-mini',
|
|
41
45
|
max_tokens: 300,
|
package/dist/config.js
CHANGED
|
@@ -107,7 +107,8 @@ export class Config {
|
|
|
107
107
|
if (!this.localEnabled)
|
|
108
108
|
return false;
|
|
109
109
|
const k = key.trim().toLowerCase();
|
|
110
|
-
|
|
110
|
+
// JWT OAuth tokens (Codex) start with 'eyj' — never route those to local
|
|
111
|
+
return this.localDummyKeys.has(k) || (k.length > 0 && !k.startsWith('sk-') && !k.startsWith('aiza') && !k.startsWith('eyj'));
|
|
111
112
|
}
|
|
112
113
|
}
|
|
113
114
|
export const config = new Config();
|
package/dist/server.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
1
4
|
import { Hono } from 'hono';
|
|
2
5
|
import { stream } from 'hono/streaming';
|
|
3
6
|
import { config } from './config.js';
|
|
@@ -13,6 +16,15 @@ const ANTHROPIC_API = 'https://api.anthropic.com';
|
|
|
13
16
|
const OPENAI_API = 'https://api.openai.com';
|
|
14
17
|
const GOOGLE_API = 'https://generativelanguage.googleapis.com';
|
|
15
18
|
const SKIP_REQ_HEADERS = new Set(['host', 'content-length', 'transfer-encoding', 'connection']);
|
|
19
|
+
function readCodexToken() {
|
|
20
|
+
try {
|
|
21
|
+
const d = JSON.parse(readFileSync(join(homedir(), '.codex', 'auth.json'), 'utf-8'));
|
|
22
|
+
return d?.tokens?.access_token ?? null;
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
16
28
|
const SKIP_RESP_HEADERS = new Set(['content-encoding', 'transfer-encoding', 'connection', 'content-length']);
|
|
17
29
|
export const stats = new Stats();
|
|
18
30
|
function forwardHeaders(headers) {
|
|
@@ -245,13 +257,23 @@ app.post('/oauth/token', async (c) => {
|
|
|
245
257
|
});
|
|
246
258
|
// ── Catch-all ─────────────────────────────────────────────────────────────────
|
|
247
259
|
app.all('*', async (c) => {
|
|
248
|
-
|
|
260
|
+
let upstream = detectUpstream(c.req.raw.headers);
|
|
249
261
|
const url = new URL(c.req.url);
|
|
250
|
-
const NEEDS_V1 = new Set(['/models', '/engines', '/files', '/embeddings', '/moderations', '/completions', '/edits']);
|
|
262
|
+
const NEEDS_V1 = new Set(['/models', '/engines', '/files', '/embeddings', '/moderations', '/completions', '/edits', '/responses']);
|
|
251
263
|
const pathname = NEEDS_V1.has(url.pathname) ? `/v1${url.pathname}` : url.pathname;
|
|
264
|
+
// /responses is exclusively an OpenAI Codex endpoint — override upstream regardless
|
|
265
|
+
// of what detectUpstream inferred from headers (Codex sends no auth to custom base URLs).
|
|
266
|
+
if (pathname === '/v1/responses')
|
|
267
|
+
upstream = OPENAI_API;
|
|
252
268
|
const targetUrl = `${upstream}${pathname}${url.search}`;
|
|
253
269
|
const body = await c.req.arrayBuffer();
|
|
254
270
|
const fwdHeaders = forwardHeaders(c.req.raw.headers);
|
|
271
|
+
// Inject Codex OAuth token from ~/.codex/auth.json when no auth header present.
|
|
272
|
+
if (upstream === OPENAI_API && !fwdHeaders['authorization']) {
|
|
273
|
+
const codexToken = readCodexToken();
|
|
274
|
+
if (codexToken)
|
|
275
|
+
fwdHeaders['authorization'] = `Bearer ${codexToken}`;
|
|
276
|
+
}
|
|
255
277
|
const resp = await fetch(targetUrl, {
|
|
256
278
|
method: c.req.method,
|
|
257
279
|
headers: fwdHeaders,
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "1.14.
|
|
1
|
+
export declare const VERSION = "1.14.5";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '1.14.
|
|
1
|
+
export const VERSION = '1.14.5';
|
package/package.json
CHANGED