@chatpanel/gateway 0.6.104 → 0.6.106

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.104",
3
+ "version": "0.6.106",
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": {
@@ -27,7 +27,7 @@
27
27
  "node": ">=18"
28
28
  },
29
29
  "dependencies": {
30
- "@chatpanel/bridge": "^0.11.23",
30
+ "@chatpanel/bridge": "^0.11.24",
31
31
  "@chatpanel/pii": "^0.7.4",
32
32
  "@huggingface/transformers": "^4.2.0",
33
33
  "onnxruntime-web": "1.26.0-dev.20260416-b7804b056c",
package/src/server.js CHANGED
@@ -63,7 +63,7 @@ import * as openai from './openai.js';
63
63
  import * as responses from './responses.js';
64
64
  import * as anthropic from './anthropic.js';
65
65
 
66
- export const VERSION = '0.6.104';
66
+ export const VERSION = '0.6.106';
67
67
 
68
68
  // WARM search tier — SQLite + FTS5 record store (falls back to an encrypted-JSON
69
69
  // store if SQLite can't load), fed by the extension's ingest sync + backup-ingest.
@@ -981,6 +981,7 @@ export function createGateway(cfg = loadConfig()) {
981
981
  // POST /v1/teams/runs/:id/answer { threadId, text, by } → { ok, run } a person answers an ask (0.6.81)
982
982
  // POST /v1/teams/runs/:id/decide { postId, status, by } → { ok, run } approve / reject a post
983
983
  // POST /v1/teams/runs/:id/post { threadId, text, kind?, replyTo?, by } → { ok, run }
984
+ // DELETE /v1/teams/runs/:id/threads/:threadId → { ok, run } a person removes a thread from the board (0.6.106)
984
985
  // POST /v1/teams/runs/:id/handoff { taskId, model, by, reason } → { ok, run } continue a task on another model (0.6.85)
985
986
  // GET /v1/teams/runs/:id/checkpoint → { ok, checkpoint } what resumeTeam needs, from the record
986
987
  // POST /v1/teams/runs/:id/claim { client } → { ok, run } a client takes a stopped/stale run over
@@ -998,7 +999,7 @@ export function createGateway(cfg = loadConfig()) {
998
999
  }
999
1000
  }
1000
1001
  {
1001
- const m = /^\/v1\/teams\/runs\/([a-zA-Z0-9_-]{4,64})(\/events|\/stop|\/answer|\/decide|\/post|\/handoff|\/checkpoint|\/claim)?$/.exec(pathname);
1002
+ const m = /^\/v1\/teams\/runs\/([a-zA-Z0-9_-]{4,64})(\/events|\/stop|\/answer|\/decide|\/post|\/handoff|\/checkpoint|\/claim|\/threads\/[a-zA-Z0-9_:-]{1,80})?$/.exec(pathname);
1002
1003
  if (m) {
1003
1004
  const id = m[1];
1004
1005
  const sub = m[2] || '';
@@ -1027,6 +1028,9 @@ export function createGateway(cfg = loadConfig()) {
1027
1028
  return sendJson(res, e.message.startsWith('no ') ? 404 : 400, { error: { message: `team run: ${e.message}`, type: 'team_error' } });
1028
1029
  }
1029
1030
  }
1031
+ if (sub.startsWith('/threads/') && req.method === 'DELETE') {
1032
+ try { return sendJson(res, 200, { ok: true, run: teamStore.removeThread(id, { threadId: sub.slice('/threads/'.length), by: 'person' }) }); } catch (e) { return sendJson(res, e.message.startsWith('no ') ? 404 : 400, { error: { message: `team run: ${e.message}`, type: 'team_error' } }); }
1033
+ }
1030
1034
  if ((sub === '/answer' || sub === '/decide' || sub === '/post') && req.method === 'POST') {
1031
1035
  try {
1032
1036
  const body = JSON.parse((await readBody(req, cfg.maxBodyBytes)).toString('utf8')) || {};
package/src/team-board.js CHANGED
@@ -105,6 +105,7 @@ export function foldBoard(state, ev) {
105
105
  if (type === 'board.thread' && p.thread?.id) {
106
106
  if (!s.threads.some((t) => t.id === p.thread.id)) s.threads.push({ ...p.thread });
107
107
  } else if (type === 'board.post' && p.post?.id) {
108
+ if (Array.isArray(s.removed) && s.removed.includes(p.post.threadId)) return s;
108
109
  if (!s.posts.some((x) => x.id === p.post.id)) s.posts.push({ ...p.post });
109
110
  const t = s.threads.find((x) => x.id === p.post.threadId);
110
111
  if (t) { t.lastAt = p.post.at; t.lastBy = p.post.by; t.posts = (t.posts || 0) + 1; }
@@ -114,6 +115,13 @@ export function foldBoard(state, ev) {
114
115
  } else if (type === 'board.thread-status' && p.threadId) {
115
116
  const t = s.threads.find((x) => x.id === p.threadId);
116
117
  if (t) { t.status = p.status; if (p.status !== 'waiting') t.waitingOn = null; if (p.holder) t.holder = p.holder; }
118
+ } else if (type === 'board.thread-removed' && p.threadId) {
119
+ // A person took the thread off the board: it and its posts go, and its id is kept so a
120
+ // post a member still makes in it (its runner did not see the removal) lands nowhere.
121
+ s.threads = s.threads.filter((x) => x.id !== p.threadId);
122
+ s.posts = s.posts.filter((x) => x.threadId !== p.threadId);
123
+ if (!Array.isArray(s.removed)) s.removed = [];
124
+ if (!s.removed.includes(p.threadId)) s.removed.push(p.threadId);
117
125
  }
118
126
  return s;
119
127
  }
@@ -124,7 +132,7 @@ export function foldBoard(state, ev) {
124
132
  * stays: a finding is a post of kind `finding` in its task's thread.
125
133
  */
126
134
  export function createBoard({ now = () => Date.now(), newId = null, state = null, onEvent = null } = {}) {
127
- const st = state && Array.isArray(state.threads) ? { threads: state.threads.map((t) => ({ ...t })), posts: (state.posts || []).map((x) => ({ ...x })) } : emptyBoardState();
135
+ const st = state && Array.isArray(state.threads) ? { threads: state.threads.map((t) => ({ ...t })), posts: (state.posts || []).map((x) => ({ ...x })), ...(Array.isArray(state.removed) && state.removed.length ? { removed: [...state.removed] } : {}) } : emptyBoardState();
128
136
  const listeners = new Set();
129
137
  let seq = st.posts.length + st.threads.length;
130
138
  const mk = (prefix) => (newId ? newId(prefix) : `${prefix}_${(++seq).toString(36)}${Math.random().toString(36).slice(2, 6)}`);
@@ -182,6 +190,20 @@ export function createBoard({ now = () => Date.now(), newId = null, state = null
182
190
  say('board.thread-status', { threadId, status, ...extra });
183
191
  return t;
184
192
  },
193
+ /**
194
+ * A person takes a thread off the board (from either client — the store appends the
195
+ * event, the running client's tail applies it here). Its posts go with it; a member's
196
+ * later post in it lands nowhere. A waiting ask is not removed: answer it or stop the run.
197
+ */
198
+ removeThread(threadId, { by = PERSON } = {}) {
199
+ const t = threadOf(threadId);
200
+ if (!t || (t.kind === 'ask' && t.status === 'waiting')) return null;
201
+ st.threads = st.threads.filter((x) => x.id !== threadId);
202
+ st.posts = st.posts.filter((x) => x.threadId !== threadId);
203
+ (st.removed ||= []).push(threadId);
204
+ say('board.thread-removed', { threadId, by });
205
+ return t;
206
+ },
185
207
  /**
186
208
  * A member is stuck: open an ask thread (status `waiting`) with the question as its
187
209
  * first post. The runner waits on it; a person answers from either client.
@@ -209,7 +231,7 @@ export function createBoard({ now = () => Date.now(), newId = null, state = null
209
231
  /** Every ask still waiting — what a client pins at the top. */
210
232
  waiting: () => st.threads.filter((t) => t.kind === 'ask' && t.status === 'waiting').map((t) => ({ ...t })),
211
233
  /** The whole board, for the run record and for a resume. */
212
- state: () => ({ threads: st.threads.map((t) => ({ ...t })), posts: st.posts.map((x) => ({ ...x })) }),
234
+ state: () => ({ threads: st.threads.map((t) => ({ ...t })), posts: st.posts.map((x) => ({ ...x })), ...(st.removed?.length ? { removed: [...st.removed] } : {}) }),
213
235
 
214
236
  // ── findings, as before: a finding is a post in its task's thread ──
215
237
  add(list, { by = null } = {}) {
@@ -71,7 +71,10 @@ export function foldRun(run, ev) {
71
71
  if (t) { t.status = 'running'; t.startedAt = at; t.error = null; }
72
72
  run.status = 'running'; break;
73
73
  }
74
- case 'task.model': { const t = taskOf(run, p.taskId); if (t) { t.model = p.model; t.attempts = [...(t.attempts || []), { model: p.model, at, attempt: p.attempt }]; } break; }
74
+ case 'task.model': { const t = taskOf(run, p.taskId); if (t) { t.model = p.model; t.attempts = [...(t.attempts || []), { model: p.model, ...(p.label ? { label: p.label } : {}), at, attempt: p.attempt }]; } break; }
75
+ // Which engine the attempt runs on (pillars §13): kept on the attempt, so a record folded
76
+ // from events names the model the way the runner's own `attempts` do.
77
+ case 'task.routed': { const t = taskOf(run, p.taskId); const a = t?.attempts?.at?.(-1); if (a && p.engine && (a.attempt == null || a.attempt === p.attempt)) a.engine = p.engine; break; }
75
78
  case 'task.step': { const t = taskOf(run, p.taskId); if (t && Array.isArray(p.steps)) t.transcript = [...(t.transcript || []), ...p.steps]; break; }
76
79
  case 'task.handoff': { const t = taskOf(run, p.taskId); if (t) { t.model = p.to; t.handoffs = [...(t.handoffs || []), { from: p.from, to: p.to, by: p.by, reason: p.reason, at }]; } break; }
77
80
  case 'task.tool': { const t = taskOf(run, p.taskId); if (t) t.tools = (t.tools || 0) + 1; break; }
@@ -97,7 +100,7 @@ export function foldRun(run, ev) {
97
100
  if (p.checkpoint) run.checkpoint = p.checkpoint;
98
101
  break;
99
102
  case 'run.stop-requested': run.stopRequested = at; break;
100
- case 'board.thread': case 'board.post': case 'board.decision': case 'board.thread-status':
103
+ case 'board.thread': case 'board.post': case 'board.decision': case 'board.thread-status': case 'board.thread-removed':
101
104
  run.threads = foldBoard(run.threads || emptyBoardState(), ev);
102
105
  if (type === 'board.thread-status' && p.status !== 'waiting' && run.status === 'waiting' && !(run.threads.threads || []).some((t) => t.kind === 'ask' && t.status === 'waiting')) run.status = 'answered';
103
106
  break;
package/src/team-store.js CHANGED
@@ -197,6 +197,19 @@ export class TeamStore {
197
197
  const post = { id: `pp_${randomBytes(4).toString('hex')}`, threadId, by: String(by || 'person').slice(0, 40), kind: ['note', 'question', 'decision'].includes(kind) ? kind : 'note', text: String(text || '').slice(0, 4000), refs: [], replyTo: replyTo || null, status: 'open', at };
198
198
  return this.append(id, [{ type: 'board.post', at, post }]);
199
199
  }
200
+ /**
201
+ * A person takes a thread off the board, from any client: the thread and its posts leave the
202
+ * record, and the running client's tail applies the same event to its live board. A waiting
203
+ * ask stays — the member behind it is blocked on an answer, not on tidiness.
204
+ */
205
+ removeThread(id, { threadId, by = 'person' } = {}) {
206
+ const run = this.runs.get(String(id || ''));
207
+ if (!run) throw new Error(`no run ${id}`);
208
+ const thread = (run.threads?.threads || []).find((t) => t.id === threadId);
209
+ if (!thread) throw new Error(`no thread ${threadId}`);
210
+ if (thread.kind === 'ask' && thread.status === 'waiting') throw new Error('an ask that is waiting cannot be removed — answer it, or stop the run');
211
+ return this.append(id, [{ type: 'board.thread-removed', at: this.now(), threadId, by: String(by || 'person').slice(0, 40) }]);
212
+ }
200
213
  /** The checkpoint a client resumes from — the runner's own when the run ended with one, else built from the record. */
201
214
  checkpoint(id) {
202
215
  const run = this.runs.get(String(id || ''));