@chatpanel/gateway 0.6.108 → 0.6.109

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chatpanel/gateway",
3
- "version": "0.6.108",
3
+ "version": "0.6.109",
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/server.js CHANGED
@@ -64,7 +64,7 @@ import * as openai from './openai.js';
64
64
  import * as responses from './responses.js';
65
65
  import * as anthropic from './anthropic.js';
66
66
 
67
- export const VERSION = '0.6.108';
67
+ export const VERSION = '0.6.109';
68
68
 
69
69
  // WARM search tier — SQLite + FTS5 record store (falls back to an encrypted-JSON
70
70
  // store if SQLite can't load), fed by the extension's ingest sync + backup-ingest.
package/src/update.js CHANGED
@@ -26,7 +26,7 @@ import os from 'node:os';
26
26
  import path from 'node:path';
27
27
  import { execFile } from 'node:child_process';
28
28
  import { chmod, rename, mkdir, readFile, writeFile, rm } from 'node:fs/promises';
29
- import { existsSync, readFileSync } from 'node:fs';
29
+ import { existsSync, readFileSync, realpathSync } from 'node:fs';
30
30
  import { restartService, serviceRegistered } from './service.js';
31
31
 
32
32
  const PACKAGE = '@chatpanel/gateway';
@@ -99,10 +99,16 @@ async function fetchJson(url, timeoutMs = FETCH_TIMEOUT_MS) {
99
99
 
100
100
  // ── the npm install, as the service launches it ───────────────────────────────────────
101
101
 
102
- /** The package root of the running npm install (…/node_modules/@chatpanel/gateway), or ''. */
103
- function npmPackageRoot() {
104
- const script = process.argv[1] ? path.resolve(process.argv[1]) : '';
105
- const m = /^(.*[/\\]node_modules[/\\]@chatpanel[/\\]gateway)[/\\]/.exec(script);
102
+ /**
103
+ * The package root of the running npm install (…/node_modules/@chatpanel/gateway), or ''.
104
+ * The service launches the bin SYMLINK (<prefix>/bin/chatpanel-gateway), whose own path says
105
+ * nothing — the realpath is what is inside node_modules. (Reading it literally classified a
106
+ * global install as "not npm" and hid the Update button behind the command.)
107
+ */
108
+ export function npmPackageRoot(script = process.argv[1]) {
109
+ let real = script ? path.resolve(script) : '';
110
+ try { real = realpathSync(real); } catch { /* a dangling link is still a clue */ }
111
+ const m = /^(.*[/\\]node_modules[/\\]@chatpanel[/\\]gateway)[/\\]/.exec(real);
106
112
  return m ? m[1] : '';
107
113
  }
108
114
  /** The version the npm install on disk reports — what the NEXT start will run. */
@@ -151,12 +157,12 @@ export async function checkForUpdate(current, { force = false } = {}) {
151
157
  const mode = isCompiledBinary() ? 'binary' : 'npm';
152
158
  if (DISABLED) return { current, latest: null, updateAvailable: false, mode, canSelfUpdate: false, assetUrl: null, stale: false, error: '', npmCommand: null, channel: mode === 'npm' ? 'npm' : 'release', service: false, disabled: true };
153
159
  const want = assetName();
154
- let latest = null; let assetUrl = null; let stale = false; let error = '';
160
+ let latest = null; let assetUrl = null; let stale = false; let error = ''; let checkedAt = 0;
155
161
  const cache = await readCache();
156
162
  const cacheFits = cache && cache.mode === mode;
157
- const fallBack = () => { latest = cacheFits ? cache.latest || null : null; assetUrl = cacheFits ? cache.assetUrl || null : null; stale = true; };
163
+ const fallBack = () => { latest = cacheFits ? cache.latest || null : null; assetUrl = cacheFits ? cache.assetUrl || null : null; checkedAt = cacheFits ? cache.checkedAt || 0 : 0; stale = true; };
158
164
  if (!force && cacheFits && Date.now() - cache.checkedAt < CHECK_EVERY_MS) {
159
- latest = cache.latest; assetUrl = cache.assetUrl;
165
+ latest = cache.latest; assetUrl = cache.assetUrl; checkedAt = cache.checkedAt;
160
166
  } else if (!force && lastFailure.at && Date.now() - lastFailure.at < RETRY_AFTER_FAILURE_MS) {
161
167
  error = lastFailure.error; fallBack();
162
168
  } else {
@@ -169,7 +175,8 @@ export async function checkForUpdate(current, { force = false } = {}) {
169
175
  latest = parseVersion(data.tag_name) || parseVersion(data.name);
170
176
  assetUrl = want ? (data.assets || []).find((a) => a.name === want)?.browser_download_url || null : null;
171
177
  }
172
- await writeCache({ checkedAt: Date.now(), mode, latest, assetUrl });
178
+ checkedAt = Date.now();
179
+ await writeCache({ checkedAt, mode, latest, assetUrl });
173
180
  lastFailure = { at: 0, error: '' };
174
181
  } catch (e) {
175
182
  error = e.message; lastFailure = { at: Date.now(), error }; fallBack();
@@ -182,7 +189,9 @@ export async function checkForUpdate(current, { force = false } = {}) {
182
189
  const canSelfUpdate = mode === 'binary' ? !!assetUrl && (process.platform !== 'win32' || serviceRegistered())
183
190
  : !!npmPackageRoot() && (process.platform !== 'win32' || (serviceRegistered() && !!npmCli()));
184
191
  const npmCommand = mode === 'npm' ? (process.platform === 'win32' ? `chatpanel-gateway --stop; npm i -g ${PACKAGE}@latest; chatpanel-gateway --install` : `npm i -g ${PACKAGE}@latest`) : null;
185
- return { current, latest, updateAvailable, mode, canSelfUpdate, assetUrl, stale, error, npmCommand, channel: mode === 'npm' ? 'npm' : 'release', service: serviceRegistered() };
192
+ // `checkedAt`: when `latest` was last a real answer — so a client can say "as of 3 h ago"
193
+ // instead of an unqualified "up to date" minutes after a publish.
194
+ return { current, latest, updateAvailable, mode, canSelfUpdate, assetUrl, stale, error, npmCommand, channel: mode === 'npm' ? 'npm' : 'release', service: serviceRegistered(), checkedAt };
186
195
  }
187
196
 
188
197
  /**
@@ -198,11 +207,11 @@ let inFlight = null;
198
207
  export function updateStatus(current) {
199
208
  const mode = isCompiledBinary() ? 'binary' : 'npm';
200
209
  if (DISABLED) return { current, latest: null, updateAvailable: false, mode, canSelfUpdate: false, stale: false, error: '', npmCommand: null, channel: mode === 'npm' ? 'npm' : 'release', service: false, disabled: true };
201
- const due = !known || (known.stale ? !(lastFailure.at && Date.now() - lastFailure.at < RETRY_AFTER_FAILURE_MS) : Date.now() - known.checkedAt > CHECK_EVERY_MS);
210
+ const due = !known || (known.stale ? !(lastFailure.at && Date.now() - lastFailure.at < RETRY_AFTER_FAILURE_MS) : Date.now() - known.seenAt > CHECK_EVERY_MS);
202
211
  if (due && !inFlight) {
203
- inFlight = checkForUpdate(current).then((r) => { known = { ...r, checkedAt: Date.now() }; }).catch(() => {}).finally(() => { inFlight = null; });
212
+ inFlight = checkForUpdate(current).then((r) => { known = { ...r, seenAt: Date.now() }; }).catch(() => {}).finally(() => { inFlight = null; });
204
213
  }
205
- if (known) return { ...known, checkedAt: undefined, current };
214
+ if (known) return { ...known, seenAt: undefined, current };
206
215
  return { current, latest: null, updateAvailable: false, mode, canSelfUpdate: false, stale: true, checking: true, error: '', npmCommand: null, channel: mode === 'npm' ? 'npm' : 'release', service: serviceRegistered() };
207
216
  }
208
217
  /** Test seam. */