@anusornneal/chat-relay 1.2.1 → 1.2.2

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/README.md CHANGED
@@ -179,7 +179,7 @@ $env:CHAT_RELAY_SOAK_ITERATIONS=100000; npm run test:soak
179
179
 
180
180
  ## Administration
181
181
 
182
- Administration is separate from the public MCP interface. The admin tooling manages users, agents, grants, lifecycle, quotas, audit data, and operational cleanup.
182
+ Administration is separate from the public MCP interface. The admin tooling manages users, agents, grants, lifecycle, audit data, and operational cleanup.
183
183
 
184
184
  Operator commands are available through:
185
185
 
@@ -490,7 +490,12 @@ function connect() {
490
490
  return;
491
491
  }
492
492
  if (message?.control === "learn_activity") {
493
- emitUi("learn", { change: message.change && typeof message.change === "object" ? message.change : {} });
493
+ const activity = message.activity && typeof message.activity === "object" ? message.activity : null;
494
+ const change = message.change && typeof message.change === "object" ? message.change : null;
495
+ emitUi("learn", {
496
+ ...(activity ? { activity } : {}),
497
+ ...(change ? { change } : {}),
498
+ });
494
499
  return;
495
500
  }
496
501
  if (message?.control === "credential_revoked") {
@@ -509,7 +514,8 @@ function connect() {
509
514
  ? String(message.payload.action ?? "unknown")
510
515
  : "unknown";
511
516
  const callSummary = humanizeToolCall(message.payload);
512
- emitUi("tool:start", { requestId: message.requestId, action, summary: callSummary });
517
+ const requestBytes = Buffer.byteLength(JSON.stringify(message), "utf8");
518
+ emitUi("tool:start", { requestId: message.requestId, action, summary: callSummary, requestBytes });
513
519
  let scheduleMeta = { lane: "unknown", queueWaitMs: 0, queueDepthAtStart: 0, activeAtStart: 0 };
514
520
  let handlerDurationMs = 0;
515
521
  try {
@@ -536,19 +542,22 @@ function connect() {
536
542
  ok: !(result && typeof result === "object" && result.ok === false),
537
543
  });
538
544
  if (recentCalls.length > 100) recentCalls.shift();
545
+ const responseMeta = {
546
+ agentQueueWaitMs: scheduleMeta.queueWaitMs,
547
+ agentHandlerMs: handlerDurationMs,
548
+ lane: scheduleMeta.lane,
549
+ };
550
+ const responseBytes = Buffer.byteLength(serializeResponse(message.requestId, result, responseMeta), "utf8");
539
551
  emitUi("tool:end", {
540
552
  requestId: message.requestId,
541
553
  action,
542
554
  summary: callSummary,
543
555
  ok: !(result && typeof result === "object" && result.ok === false),
544
556
  durationMs: Date.now() - startedAt,
557
+ responseBytes,
545
558
  ...(result && typeof result === "object" && result.ok === false && result.error ? { error: String(result.error) } : {}),
546
559
  });
547
- sendSocketResponse(socket, message.requestId, result, {
548
- agentQueueWaitMs: scheduleMeta.queueWaitMs,
549
- agentHandlerMs: handlerDurationMs,
550
- lane: scheduleMeta.lane,
551
- });
560
+ sendSocketResponse(socket, message.requestId, result, responseMeta);
552
561
  } catch (error) {
553
562
  recentCalls.push({
554
563
  at: new Date().toISOString(),
@@ -562,18 +571,21 @@ function connect() {
562
571
  error: error instanceof Error ? error.message : "agent_error",
563
572
  });
564
573
  if (recentCalls.length > 100) recentCalls.shift();
574
+ const errorPayload = {
575
+ ok: false,
576
+ error: error instanceof Error ? error.message : "agent_error",
577
+ };
578
+ const responseBytes = Buffer.byteLength(serializeResponse(message.requestId, errorPayload), "utf8");
565
579
  emitUi("tool:end", {
566
580
  requestId: message.requestId,
567
581
  action,
568
582
  summary: callSummary,
569
583
  ok: false,
570
584
  durationMs: Date.now() - startedAt,
571
- error: error instanceof Error ? error.message : "agent_error",
572
- });
573
- sendSocketResponse(socket, message.requestId, {
574
- ok: false,
575
- error: error instanceof Error ? error.message : "agent_error",
585
+ responseBytes,
586
+ error: errorPayload.error,
576
587
  });
588
+ sendSocketResponse(socket, message.requestId, errorPayload);
577
589
  }
578
590
  });
579
591
 
package/cli/tui.mjs CHANGED
@@ -191,6 +191,13 @@ function formatDuration(ms, status) {
191
191
  return (value / 1000).toFixed(value < 10000 ? 1 : 0) + "s";
192
192
  }
193
193
 
194
+ export function formatBytes(bytes) {
195
+ const value = Math.max(0, Number(bytes) || 0);
196
+ if (value < 1024) return Math.round(value) + " B";
197
+ if (value < 1024 * 1024) return (value / 1024).toFixed(value < 10 * 1024 ? 1 : 0) + " KB";
198
+ return (value / (1024 * 1024)).toFixed(value < 10 * 1024 * 1024 ? 1 : 0) + " MB";
199
+ }
200
+
194
201
  function clock(value) {
195
202
  const date = value ? new Date(value) : new Date();
196
203
  if (Number.isNaN(date.getTime())) return "--:--:--";
@@ -239,7 +246,11 @@ export function formatTransactionRows(item, width = 110, { color = false } = {})
239
246
  const prefixWidth = terminalCellWidth(prefix);
240
247
  const continuationPrefix = " ".repeat(prefixWidth);
241
248
  const duration = formatDuration(item.durationMs, item.status);
242
- const suffix = " " + duration.padStart(8);
249
+ const transfer = [
250
+ Number.isFinite(Number(item.requestBytes)) ? "↑ " + formatBytes(item.requestBytes) : null,
251
+ Number.isFinite(Number(item.responseBytes)) ? "↓ " + formatBytes(item.responseBytes) : null,
252
+ ].filter(Boolean).join(" ");
253
+ const suffix = " " + (transfer ? transfer + " " : "") + duration.padStart(8);
243
254
  const summaryWidth = Math.max(4, usable - prefixWidth - terminalCellWidth(suffix));
244
255
  const summaryLines = wrapText(item.summary || item.action || "Tool call", summaryWidth, 3);
245
256
 
@@ -464,6 +475,7 @@ export class RemoteTui {
464
475
  summary: message.summary || humanizeToolCall({ action: message.action }),
465
476
  status: "running",
466
477
  ok: null,
478
+ requestBytes: Number.isFinite(Number(message.requestBytes)) ? Number(message.requestBytes) : undefined,
467
479
  });
468
480
  } else if (message.event === "tool:end") {
469
481
  const item = [...this.transactions].reverse().find((entry) => entry.requestId === message.requestId);
@@ -471,26 +483,69 @@ export class RemoteTui {
471
483
  item.status = "done";
472
484
  item.ok = message.ok !== false;
473
485
  item.durationMs = message.durationMs;
486
+ if (Number.isFinite(Number(message.responseBytes))) item.responseBytes = Number(message.responseBytes);
474
487
  if (message.error && message.ok === false) item.summary += ` · ${truncate(message.error, 48)}`;
475
488
  }
476
489
  } else if (message.event === "learn") {
477
- const change = message.change && typeof message.change === "object" ? message.change : {};
478
- const marker = {
479
- created: "+",
480
- updated: "~",
481
- reinforced: "^",
482
- weakened: "v",
483
- removed: "-",
484
- }[String(change.type || "")] || "~";
485
- const detail = String(change.summary || change.key || "Learn updated").replace(/\s+/g, " ").trim();
486
- this.appendTransaction({
487
- requestId: "learn-" + String(change.eventId || Date.now()),
488
- at: change.at || message.at || new Date().toISOString(),
489
- action: "learn",
490
- summary: "Learn " + marker + " " + truncate(detail, 120),
491
- status: "done",
492
- ok: true,
493
- });
490
+ const activity = message.activity && typeof message.activity === "object" ? message.activity : null;
491
+ if (activity) {
492
+ const tool = String(activity.tool || "learn");
493
+ const change = activity.change && typeof activity.change === "object" ? activity.change : null;
494
+ const scopeSummary = String(activity.scopeSummary || "").trim();
495
+ const kind = String(change?.kind || activity.kind || "memory").trim() || "memory";
496
+ const key = String(change?.key || "").trim();
497
+ const verbs = {
498
+ created: "created",
499
+ updated: "updated",
500
+ reinforced: "reinforced",
501
+ weakened: "weakened",
502
+ removed: "removed",
503
+ };
504
+ let detail;
505
+ if (tool === "learn_prepare") {
506
+ detail = "prepare " + (scopeSummary || "relevant") + " context";
507
+ } else if (tool === "learn_get") {
508
+ detail = "read " + (scopeSummary || "memory") + " context";
509
+ } else if (change) {
510
+ detail = (verbs[String(change.type || "")] || "updated") + " " + kind + (key ? " · " + key : "");
511
+ } else if (tool === "learn_put") {
512
+ detail = "write " + kind + " · no change";
513
+ } else if (tool === "learn_delete") {
514
+ detail = "delete memory · no change";
515
+ } else if (tool === "learn_feedback") {
516
+ detail = String(activity.feedback || "feedback") + " memory · no change";
517
+ } else {
518
+ detail = tool.replace(/^learn_/, "").replace(/_/g, " ");
519
+ }
520
+ const durationMs = Number(activity.durationMs);
521
+ this.appendTransaction({
522
+ requestId: String(activity.eventId || "learn-call-" + Date.now()),
523
+ at: activity.at || message.at || new Date().toISOString(),
524
+ action: tool,
525
+ summary: "🧠 Learn · " + truncate(detail, 120),
526
+ status: "done",
527
+ ok: activity.ok !== false,
528
+ ...(Number.isFinite(durationMs) ? { durationMs } : {}),
529
+ });
530
+ } else {
531
+ const change = message.change && typeof message.change === "object" ? message.change : {};
532
+ const marker = {
533
+ created: "+",
534
+ updated: "~",
535
+ reinforced: "^",
536
+ weakened: "v",
537
+ removed: "-",
538
+ }[String(change.type || "")] || "~";
539
+ const detail = String(change.summary || change.key || "Learn updated").replace(/\s+/g, " ").trim();
540
+ this.appendTransaction({
541
+ requestId: "learn-" + String(change.eventId || Date.now()),
542
+ at: change.at || message.at || new Date().toISOString(),
543
+ action: "learn",
544
+ summary: "Learn " + marker + " " + truncate(detail, 120),
545
+ status: "done",
546
+ ok: true,
547
+ });
548
+ }
494
549
  } else if (message.event === "system") {
495
550
  this.appendTransaction({
496
551
  requestId: "system-" + Date.now() + "-" + Math.random(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anusornneal/chat-relay",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "Zero-checkout remote MCP agent for ChatGPT with terminal, filesystem, process, multi-user, and multi-agent support.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -40,11 +40,11 @@
40
40
  "test:oauth": "node test/oauth-smoke.mjs",
41
41
  "test:usage": "node test/usage-smoke.mjs",
42
42
  "test:usage-storage": "node test/usage-storage.test.mjs",
43
+ "test:no-quota": "node test/no-quota-regression.test.mjs",
43
44
  "test:admin-api": "node test/admin-api-smoke.mjs",
44
45
  "test:admin-auth": "node test/admin-auth-smoke.mjs",
45
46
  "test:dashboard": "node test/dashboard-smoke.mjs",
46
47
  "test:dashboard-timers": "node test/dashboard-timers.test.mjs",
47
- "test:quota": "node test/quota-smoke.mjs",
48
48
  "test:ops": "node test/ops-smoke.mjs",
49
49
  "test:desktop": "node test/mcp-desktop-smoke.mjs",
50
50
  "test:device-management": "node test/device-management-smoke.mjs",
@@ -55,10 +55,11 @@
55
55
  "test:self-update": "node --test test/self-update.test.mjs test/agent-lifecycle-upgrade.test.mjs",
56
56
  "test:budget": "node --test test/relay-health.test.mjs test/usage-budget.test.mjs",
57
57
  "test:soak": "node test/soak-smoke.mjs",
58
- "test:hardening": "npm run test:tui && npm run test:config-security && npm run test:self-update && npm run test:budget && node --test test/connection-generation.test.mjs && npm run test:agent-state && node test/heartbeat-ack-watchdog.test.mjs && npm run test:usage-storage && npm run test:learn && npm run test:learn-bootstrap && npm run test:soak",
58
+ "test:hardening": "npm run test:tui && npm run test:config-security && npm run test:self-update && npm run test:budget && npm run test:worker-hotpath && node --test test/connection-generation.test.mjs && npm run test:agent-state && node test/heartbeat-ack-watchdog.test.mjs && npm run test:no-quota && npm run test:usage-storage && npm run test:learn && npm run test:learn-bootstrap && npm run test:soak",
59
59
  "verify:review": "node scripts/verify-review-artifacts.mjs",
60
60
  "test:learn": "node test/learning-smoke.mjs",
61
- "test:learn-bootstrap": "node test/learning-bootstrap-smoke.mjs"
61
+ "test:learn-bootstrap": "node test/learning-bootstrap-smoke.mjs",
62
+ "test:worker-hotpath": "node --experimental-strip-types --test test/relay-result.test.mjs"
62
63
  },
63
64
  "dependencies": {
64
65
  "ws": "^8.22.0"