@chatpanel/gateway 0.6.108 → 0.6.110
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/server.js +9 -3
- package/src/team-store.js +1 -1
- package/src/update.js +22 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chatpanel/gateway",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.110",
|
|
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.
|
|
67
|
+
export const VERSION = '0.6.110';
|
|
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.
|
|
@@ -1005,7 +1005,7 @@ export function createGateway(cfg = loadConfig()) {
|
|
|
1005
1005
|
// GET /v1/teams/runs/:id/checkpoint → { ok, checkpoint } what resumeTeam needs, from the record
|
|
1006
1006
|
// POST /v1/teams/runs/:id/claim { client } → { ok, run } a client takes a stopped/stale run over
|
|
1007
1007
|
// POST /v1/teams/runs/:id/stop → { ok, run } a stop request any client may make
|
|
1008
|
-
// DELETE /v1/teams/runs/:id → { ok, removed }
|
|
1008
|
+
// DELETE /v1/teams/runs/:id → { ok, removed } a live run is stopped first (0.6.110)
|
|
1009
1009
|
if (pathname === '/v1/teams/runs' && req.method === 'GET') {
|
|
1010
1010
|
return sendJson(res, 200, { ok: true, runs: teamStore.list({ limit: url.searchParams.get('limit') || 50, team: url.searchParams.get('team') || '' }) });
|
|
1011
1011
|
}
|
|
@@ -1026,7 +1026,13 @@ export function createGateway(cfg = loadConfig()) {
|
|
|
1026
1026
|
const run = teamStore.get(id, { events: url.searchParams.get('events') === '1' });
|
|
1027
1027
|
return run ? sendJson(res, 200, { ok: true, run }) : sendJson(res, 404, { error: { message: `no run ${id}`, type: 'not_found' } });
|
|
1028
1028
|
}
|
|
1029
|
-
if (!sub && req.method === 'DELETE')
|
|
1029
|
+
if (!sub && req.method === 'DELETE') {
|
|
1030
|
+
// A live run is stopped BEFORE its record goes (0.6.110), so the client running it
|
|
1031
|
+
// hears `run.stop-requested` on its tail. Removing the record alone left the member
|
|
1032
|
+
// working on for a run nobody could see, its appends failing until it gave up.
|
|
1033
|
+
teamStore.stop(id);
|
|
1034
|
+
return sendJson(res, 200, { ok: true, removed: teamStore.remove(id) });
|
|
1035
|
+
}
|
|
1030
1036
|
if (sub === '/stop' && req.method === 'POST') {
|
|
1031
1037
|
const run = teamStore.stop(id);
|
|
1032
1038
|
return run ? sendJson(res, 200, { ok: true, run }) : sendJson(res, 404, { error: { message: `no run ${id}`, type: 'not_found' } });
|
package/src/team-store.js
CHANGED
|
@@ -252,7 +252,7 @@ export class TeamStore {
|
|
|
252
252
|
}
|
|
253
253
|
remove(id) {
|
|
254
254
|
const had = this.runs.delete(String(id || ''));
|
|
255
|
-
if (had) this.save();
|
|
255
|
+
if (had) { this.watchers.delete(String(id || '')); this.save(); }
|
|
256
256
|
return had;
|
|
257
257
|
}
|
|
258
258
|
get size() { return this.runs.size; }
|
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
|
-
/**
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
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,
|
|
212
|
+
inFlight = checkForUpdate(current).then((r) => { known = { ...r, seenAt: Date.now() }; }).catch(() => {}).finally(() => { inFlight = null; });
|
|
204
213
|
}
|
|
205
|
-
if (known) return { ...known,
|
|
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. */
|