@aexol/spectral 0.2.18 → 0.2.20

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.
@@ -656,6 +656,10 @@ export class PiBridge {
656
656
  if (this.disposed)
657
657
  return;
658
658
  this.disposed = true;
659
+ // Persist the current in-flight message (if any) before tearing down.
660
+ // Without this, cancelling mid-turn loses the message along with its
661
+ // token_usage event, which breaks context-window tracking on reconnect.
662
+ this.finalizePendingMessage();
659
663
  try {
660
664
  this.unsubscribe?.();
661
665
  }
@@ -829,8 +833,17 @@ export class PiBridge {
829
833
  // Emit token usage for this assistant message. pi provides token
830
834
  // counts via ev.message.usage; cost is computed from the model's
831
835
  // configured pricing (or null when unavailable).
836
+ //
837
+ // Skip zero-total-usage events — they happen when a turn is
838
+ // cancelled before the provider starts streaming, and emitting
839
+ // inputTokens:0 would mislead the UI into showing 0% context window
840
+ // usage after reconnect.
832
841
  const usage = ev.message.usage;
833
- if (usage) {
842
+ const totalTokens = (usage?.input ?? 0) +
843
+ (usage?.output ?? 0) +
844
+ (usage?.cacheRead ?? 0) +
845
+ (usage?.cacheWrite ?? 0);
846
+ if (usage && totalTokens > 0) {
834
847
  const usageEvent = {
835
848
  type: "token_usage",
836
849
  messageId,
@@ -839,7 +852,7 @@ export class PiBridge {
839
852
  outputTokens: usage.output ?? 0,
840
853
  cacheReadTokens: usage.cacheRead ?? 0,
841
854
  cacheWriteTokens: usage.cacheWrite ?? 0,
842
- totalTokens: usage.totalTokens ?? 0,
855
+ totalTokens: usage.totalTokens ?? totalTokens,
843
856
  cost: usage.cost?.total ?? null,
844
857
  },
845
858
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aexol/spectral",
3
- "version": "0.2.18",
3
+ "version": "0.2.20",
4
4
  "description": "Always-on coding agent for Aexol — branded pi wrapper with relay-based browser access.",
5
5
  "type": "module",
6
6
  "private": false,