@tiens.nguyen/gonext-local-worker 1.0.314 → 1.0.316

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.
@@ -5052,8 +5052,27 @@ def run_agent_chat(cfg):
5052
5052
  pass
5053
5053
  break
5054
5054
  content = "".join(parts)
5055
+ # Fallback OUTPUT-token count (task #112): some OpenAI-compatible servers (seen
5056
+ # live: Moonshot/Kimi K3) don't emit a final usage chunk on every streamed call,
5057
+ # and the runaway guard closes the stream BEFORE the trailing usage chunk — so a
5058
+ # step that DID generate output reports completion_tokens=0 and contributes
5059
+ # nothing to the per-turn "↓ out" total (~3x under-count on reasoning models,
5060
+ # whose output is mostly reasoning-channel tokens). When the server reported no
5061
+ # completion tokens, estimate from the streamed OUTPUT chars (visible content +
5062
+ # reasoning, ~4 chars/token, matching the #83 input estimate) so no generating
5063
+ # step silently counts 0. Authoritative server usage always wins when present
5064
+ # (out_tok>0), so Ollama — which always reports usage — is unchanged; MLX, which
5065
+ # reports none, now gets an estimate instead of a hard 0.
5066
+ if out_tok <= 0:
5067
+ approx_chars = len(content) + reasoning_len
5068
+ if approx_chars > 0:
5069
+ out_tok = max(1, (approx_chars + 3) // 4)
5070
+ _log(f"streamed generate: server reported no completion tokens → "
5071
+ f"estimated out≈{out_tok} tokens from {approx_chars} streamed "
5072
+ "chars (content+reasoning) (#112)")
5055
5073
  if _runaway:
5056
5074
  # Discard the garbage; "" makes _streamed_generate run the CODE-NOW retry.
5075
+ # Keep out_tok (the estimate above) — those tokens WERE generated/billed.
5057
5076
  _emit({"type": "step", "text": "Model output ran away — restarting this step…"})
5058
5077
  _log(f"streamed generate: discarded {len(content)} runaway chars → empty content")
5059
5078
  return "", role, in_tok, out_tok, reasoning_len
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiens.nguyen/gonext-local-worker",
3
- "version": "1.0.314",
3
+ "version": "1.0.316",
4
4
  "description": "Polls GoNext cloud API for async local LLM jobs and runs them against Ollama/OpenAI-compatible servers on this Mac",
5
5
  "type": "module",
6
6
  "license": "MIT",