@chatpanel/gateway 0.6.8 → 0.6.10
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/package.json +1 -1
- package/src/config.js +11 -0
- package/src/log.js +21 -0
- package/src/server.js +17 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chatpanel/gateway",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.10",
|
|
4
4
|
"description": "Local privacy gateway — redacts PII out of OpenAI/Anthropic API traffic before it reaches a model, then restores it in the reply. Point opencode, codex, aider, Claude Code, etc. at it.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
package/src/config.js
CHANGED
|
@@ -139,5 +139,16 @@ export function loadConfig(env = process.env) {
|
|
|
139
139
|
if (env.ANTHROPIC_BASE_URL) cfg = deepMerge(cfg, { upstreams: { anthropic: { baseUrl: env.ANTHROPIC_BASE_URL } } });
|
|
140
140
|
if (env.CHATPANEL_REDACTION_TIER) cfg = deepMerge(cfg, { redaction: { tier: env.CHATPANEL_REDACTION_TIER } });
|
|
141
141
|
|
|
142
|
+
// A persisted port of 0 means "let the OS pick a random port" — fatal for a
|
|
143
|
+
// service that clients reach at a FIXED address: the extension, install.sh, and
|
|
144
|
+
// OpenCode/Pi all hardcode 4320. A stale/corrupt config that wrote 0 would bind a
|
|
145
|
+
// random ephemeral port and look "running but unreachable". Coerce 0 / NaN / out-
|
|
146
|
+
// of-range back to the default so the gateway is always where clients expect it.
|
|
147
|
+
const p = Number(cfg.port);
|
|
148
|
+
if (!Number.isInteger(p) || p < 1 || p > 65535) {
|
|
149
|
+
if (cfg.port !== DEFAULTS.port) console.warn(`[gateway] ignoring invalid port ${JSON.stringify(cfg.port)} — using ${DEFAULTS.port}`);
|
|
150
|
+
cfg = deepMerge(cfg, { port: DEFAULTS.port });
|
|
151
|
+
}
|
|
152
|
+
|
|
142
153
|
return cfg;
|
|
143
154
|
}
|
package/src/log.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Timestamped console. Gateway logs (NER lifecycle, per-request redaction lines,
|
|
2
|
+
// entitlement refresh) are useless for debugging without a clock — prefix every
|
|
3
|
+
// console line with a local YYYY-MM-DD HH:MM:SS stamp. Call once at startup,
|
|
4
|
+
// before anything logs. Idempotent (won't double-wrap if called twice).
|
|
5
|
+
|
|
6
|
+
let installed = false;
|
|
7
|
+
|
|
8
|
+
function stamp(d = new Date()) {
|
|
9
|
+
const p = (n, w = 2) => String(n).padStart(w, '0');
|
|
10
|
+
return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} `
|
|
11
|
+
+ `${p(d.getHours())}:${p(d.getMinutes())}:${p(d.getSeconds())}`;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function installTimestampedConsole() {
|
|
15
|
+
if (installed) return;
|
|
16
|
+
installed = true;
|
|
17
|
+
for (const method of ['log', 'info', 'warn', 'error']) {
|
|
18
|
+
const orig = console[method].bind(console);
|
|
19
|
+
console[method] = (...args) => orig(`[${stamp()}]`, ...args);
|
|
20
|
+
}
|
|
21
|
+
}
|
package/src/server.js
CHANGED
|
@@ -27,6 +27,7 @@ import { streamBridgeChat, readBridgeToken, openBridgeChat } from './bridge.js';
|
|
|
27
27
|
import { createRelaySession, getRelaySession, endRelaySession, pumpBridgeStream, deliverToolResult, toolsToSpecs, parseToolCallId } from './toolrelay.js';
|
|
28
28
|
import { shaperFor } from './shape.js';
|
|
29
29
|
import { startNer } from './ner.js';
|
|
30
|
+
import { installTimestampedConsole } from './log.js';
|
|
30
31
|
import * as nerEngine from './ner-engine.js';
|
|
31
32
|
import { MODEL_CATALOG, isKnownModel } from './models.js';
|
|
32
33
|
import { resolvePro, checkQuota, consume, usage } from './freegate.js';
|
|
@@ -36,7 +37,7 @@ import * as openai from './openai.js';
|
|
|
36
37
|
import * as responses from './responses.js';
|
|
37
38
|
import * as anthropic from './anthropic.js';
|
|
38
39
|
|
|
39
|
-
export const VERSION = '0.6.
|
|
40
|
+
export const VERSION = '0.6.10';
|
|
40
41
|
|
|
41
42
|
const KNOWN_AGENTS = new Set(['codex', 'claude', 'opencode', 'pi', 'kiro', 'antigravity']);
|
|
42
43
|
|
|
@@ -704,12 +705,27 @@ export function createGateway(cfg = loadConfig()) {
|
|
|
704
705
|
}
|
|
705
706
|
|
|
706
707
|
export function start(cfg = loadConfig()) {
|
|
708
|
+
installTimestampedConsole(); // every gateway log line gets a clock — before anything logs
|
|
707
709
|
const server = createGateway(cfg);
|
|
708
710
|
const ner = startNer(cfg); // may mutate cfg.redaction when it comes up
|
|
709
711
|
// Re-validate the stored Pro entitlement online on an interval, so a refunded /
|
|
710
712
|
// revoked subscription drops the gateway to Free instead of riding the offline
|
|
711
713
|
// token to its exp (see entitlement-refresh.js).
|
|
712
714
|
const entitlement = startEntitlementRefresh(cfg);
|
|
715
|
+
// Fail LOUD on a port clash instead of crashing with a raw stack trace. We bind a
|
|
716
|
+
// FIXED port (4320) so the extension / install.sh / OpenCode can always find us; if
|
|
717
|
+
// something else already holds it, tell the user exactly how to recover (pick a new
|
|
718
|
+
// port, restart, and point the extension's Gateway tab at it) rather than silently
|
|
719
|
+
// dying or drifting to a random port.
|
|
720
|
+
server.on('error', (e) => {
|
|
721
|
+
if (e && e.code === 'EADDRINUSE') {
|
|
722
|
+
console.error(`Port ${cfg.port} is already in use — another app (or a second gateway) has it.`);
|
|
723
|
+
console.error(`Fix: free the port, or set a different one — edit "port" in ${configPath()} (or the extension's Gateway tab) and restart. The extension must point at the same port.`);
|
|
724
|
+
process.exit(1);
|
|
725
|
+
}
|
|
726
|
+
console.error(`Gateway server error: ${e?.message || e}`);
|
|
727
|
+
process.exit(1);
|
|
728
|
+
});
|
|
713
729
|
server.listen(cfg.port, cfg.host, () => {
|
|
714
730
|
console.log(`ChatPanel Privacy Gateway v${VERSION} on http://${cfg.host}:${cfg.port}`);
|
|
715
731
|
console.log(` backend : ${cfg.backend}` + (cfg.backend === 'bridge' ? ` (agent: ${cfg.bridge.agent}, via ${cfg.bridge.url})` : ''));
|