@melaya/runner 1.0.111 → 1.0.114

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.
Files changed (2) hide show
  1. package/dist/assistantHost.py +40 -0
  2. package/package.json +42 -42
@@ -72,6 +72,40 @@ def _memory_watermark(agent) -> int:
72
72
  return 0
73
73
 
74
74
 
75
+ def _emit_usage(agent, turn_id: str) -> None:
76
+ """Live header meter (runner parity): the context-fullness GAUGE — memory
77
+ watermark vs budget — so the FE shows how full the window is before the next
78
+ compaction, exactly like the cloud path. Per-turn TOKEN totals are exported as
79
+ spans (Overview dashboard); the live in/out counter stays cloud-only for now."""
80
+ try:
81
+ mem = _agent_memory(agent)
82
+ if mem is None:
83
+ return
84
+ budget = int(getattr(mem, "max_tokens", 0) or 0)
85
+ # Real context fullness = current retained-content tokens (NOT the rehydration
86
+ # watermark, which reads ~0). Falls back to 0 on an old shared bundle without
87
+ # current_tokens() — the gauge just won't move until the bundle updates.
88
+ used = int(mem.current_tokens()) if hasattr(mem, "current_tokens") else 0
89
+ # Live in/out tokens for THIS turn: force-flush the pending trace spans, then
90
+ # drain the exporter's accumulator (the SAME tokens that land in agents.spans).
91
+ # The BatchSpanProcessor exports asynchronously, so flush first or the turn's
92
+ # spans may not have been counted yet. Best-effort; 0 on an old shared bundle.
93
+ in_tok = out_tok = 0
94
+ try:
95
+ from opentelemetry import trace as _ot
96
+ tp = _ot.get_tracer_provider()
97
+ if hasattr(tp, "force_flush"):
98
+ tp.force_flush()
99
+ from shared.runtime.tracing_exporter import drain_token_totals
100
+ in_tok, out_tok = drain_token_totals()
101
+ except Exception:
102
+ pass
103
+ if budget > 0 or in_tok or out_tok:
104
+ _emit(turn_id, "usage", turnInTok=int(in_tok), turnOutTok=int(out_tok), ctxUsed=used, ctxBudget=budget)
105
+ except Exception:
106
+ pass
107
+
108
+
75
109
  def _sync_ollama_memory_budget(agent) -> None:
76
110
  """P2-6 (persistent host): the Assistant builds ONE agent + BoundedMemory, so an
77
111
  OOM num_ctx downgrade that shrinks the ollama context cache would otherwise leave
@@ -392,6 +426,11 @@ def _build_agent():
392
426
  "to find the right content yourself. Keep going until the task is COMPLETE (e.g. "
393
427
  "all N comments posted) or you are genuinely blocked; only then report what you "
394
428
  "did and what (if anything) is blocked.\n"
429
+ "- NEVER fabricate a reason for stopping. Do NOT claim 'the connection dropped', "
430
+ "'I lost connection', 'the session ended' or invent ANY infra failure — you "
431
+ "cannot observe that and it is almost always false. If a phone action is slow or "
432
+ "errors, RETRY it; only if it truly won't recover after retries do you stop, and "
433
+ "then state the EXACT tool that failed + what the screen showed.\n"
395
434
  if phone_enabled else ""
396
435
  )
397
436
  connector_rule = (
@@ -761,6 +800,7 @@ def main() -> int:
761
800
  # the ollama context (no-op for every other provider / when unchanged).
762
801
  _sync_ollama_memory_budget(agent)
763
802
  _run_turn(agent, turn_id, message)
803
+ _emit_usage(agent, turn_id)
764
804
 
765
805
 
766
806
  if __name__ == "__main__":
package/package.json CHANGED
@@ -1,42 +1,42 @@
1
- {
2
- "name": "@melaya/runner",
3
- "version": "1.0.111",
4
- "description": "Run Melaya AI pipelines locally with your own LM Studio or Ollama models",
5
- "license": "UNLICENSED",
6
- "private": false,
7
- "type": "module",
8
- "bin": {
9
- "melaya-runner": "dist/cli.js"
10
- },
11
- "main": "dist/index.js",
12
- "files": [
13
- "dist/**/*.js",
14
- "dist/**/*.d.ts",
15
- "dist/**/*.py",
16
- "localRagIngest.py",
17
- "localRagRetrieve.py",
18
- "nltk_data/**",
19
- "README.md"
20
- ],
21
- "scripts": {
22
- "build": "tsc && node -e \"const fs=require('fs'); fs.copyFileSync('localRagIngest.py','dist/localRagIngest.py'); fs.copyFileSync('localRagRetrieve.py','dist/localRagRetrieve.py'); fs.copyFileSync('src/assistantHost.py','dist/assistantHost.py')\"",
23
- "prepublishOnly": "npm run build"
24
- },
25
- "dependencies": {
26
- "chalk": "^5.3.0",
27
- "commander": "^12.0.0",
28
- "ora": "^8.0.0",
29
- "playwright": "^1.47.0",
30
- "socket.io-client": "^4.8.0"
31
- },
32
- "devDependencies": {
33
- "@types/node": "^20.0.0",
34
- "typescript": "^5.5.0"
35
- },
36
- "engines": {
37
- "node": ">=18"
38
- },
39
- "publishConfig": {
40
- "access": "public"
41
- }
42
- }
1
+ {
2
+ "name": "@melaya/runner",
3
+ "version": "1.0.114",
4
+ "description": "Run Melaya AI pipelines locally with your own LM Studio or Ollama models",
5
+ "license": "UNLICENSED",
6
+ "private": false,
7
+ "type": "module",
8
+ "bin": {
9
+ "melaya-runner": "dist/cli.js"
10
+ },
11
+ "main": "dist/index.js",
12
+ "files": [
13
+ "dist/**/*.js",
14
+ "dist/**/*.d.ts",
15
+ "dist/**/*.py",
16
+ "localRagIngest.py",
17
+ "localRagRetrieve.py",
18
+ "nltk_data/**",
19
+ "README.md"
20
+ ],
21
+ "scripts": {
22
+ "build": "tsc && node -e \"const fs=require('fs'); fs.copyFileSync('localRagIngest.py','dist/localRagIngest.py'); fs.copyFileSync('localRagRetrieve.py','dist/localRagRetrieve.py'); fs.copyFileSync('src/assistantHost.py','dist/assistantHost.py')\"",
23
+ "prepublishOnly": "npm run build"
24
+ },
25
+ "dependencies": {
26
+ "chalk": "^5.3.0",
27
+ "commander": "^12.0.0",
28
+ "ora": "^8.0.0",
29
+ "playwright": "^1.47.0",
30
+ "socket.io-client": "^4.8.0"
31
+ },
32
+ "devDependencies": {
33
+ "@types/node": "^20.0.0",
34
+ "typescript": "^5.5.0"
35
+ },
36
+ "engines": {
37
+ "node": ">=18"
38
+ },
39
+ "publishConfig": {
40
+ "access": "public"
41
+ }
42
+ }