@melaya/runner 1.0.108 → 1.0.110

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.
@@ -142,7 +142,7 @@ _CANCELLED = object()
142
142
  class _RedactingStdout:
143
143
  """Wrap stdout to strip long base64 runs before they reach the log.
144
144
 
145
- agentscope prints every agent message verbatim (the `MelayaAssistant: {...}`
145
+ agentscope prints every agent message verbatim (the `Assistant: {...}`
146
146
  lines), which for phone_screenshot tool results embeds a full base64 JPEG —
147
147
  tens of KB per turn that floods and explodes the runner logs. This filter is
148
148
  line-buffered and only replaces base64-looking runs (>=200 chars), so the
@@ -407,7 +407,13 @@ def _build_agent():
407
407
  )
408
408
 
409
409
  agent = make_agent(
410
- name="MelayaAssistant",
410
+ # This name IS the agent identity that agentscope stamps onto the traced
411
+ # `invoke_agent <name>` span + gen_ai.agent.name — which is EXACTLY the
412
+ # dimension the Overview "by agent" token breakdown groups on
413
+ # (agentStudio.ts:4173/4258). So naming it "Assistant" makes every
414
+ # runner-assistant turn roll up under an "Assistant" agent in the dashboard
415
+ # automatically, no dashboard code change.
416
+ name="Assistant",
411
417
  sys_prompt=sys_prompt,
412
418
  toolkit=toolkit,
413
419
  model_name=model,
@@ -421,8 +427,11 @@ def _build_agent():
421
427
  # the task is finished. Give phone runs real headroom (they are HITL-gated,
422
428
  # so each write still needs the user's tap — cost stays bounded). Connector
423
429
  # WRITE fan-outs (1 list + N sends, each its own reasoning+HITL round) keep
424
- # the 40 that fits them; read-only Q&A needs very few.
425
- max_iters=100 if phone_enabled else (40 if connector_services else 8),
430
+ # the 40 that fits them; read-only Q&A needs very few. Phone raised + env-tunable
431
+ # for long-horizon tasks (100s of steps) now that per-step tokens are pruned +
432
+ # cached; each write is still HITL-gated so cost stays bounded.
433
+ max_iters=(int(os.environ.get("MEL_ASSISTANT_MAX_ITERS_PHONE", "300") or "300") if phone_enabled
434
+ else (40 if connector_services else 8)),
426
435
  reliability=True,
427
436
  bounded_memory=True,
428
437
  )
@@ -611,6 +620,19 @@ def _stdin_reader(q: "queue.Queue[str]") -> None:
611
620
 
612
621
  def main() -> int:
613
622
  _log(f"booting (provider={os.environ.get('MEL_ASSISTANT_PROVIDER')})")
623
+ # Wire OpenTelemetry → Melaya event relay so agentscope's @trace_llm actually
624
+ # exports token spans to agents.spans — the SAME thing pipelines get via
625
+ # events.setup_studio_forwarder(). Without this the trace gate stays off AND
626
+ # the exporter is disabled, so every claude_code/codex assistant turn recorded
627
+ # ZERO tokens (no Overview cost row, no per-turn token count). The exporter
628
+ # self-gates on MEL_BUILDER_URL + MEL_RUN_ID (both set by the runner spawn);
629
+ # idempotent + best-effort — a tracing failure NEVER blocks a turn.
630
+ try:
631
+ from shared.runtime.tracing_exporter import setup_melaya_tracing
632
+ setup_melaya_tracing()
633
+ _log("tracing wired (spans → agents.spans)")
634
+ except Exception:
635
+ _log("tracing setup unavailable (non-fatal)")
614
636
  # Mirror the spawn-time assistant autonomy mode into MEL_HITL_MODE so the
615
637
  # in-process phone tools (phone.py._cmd) see it from turn one.
616
638
  _apply_hitl_mode(None)
@@ -1011,6 +1011,15 @@ export async function connect(opts) {
1011
1011
  // consistent across surfaces. assistantHost mirrors MEL_ASSISTANT_HITL_MODE
1012
1012
  // → MEL_HITL_MODE so phone.py stamps the mode on the command body.
1013
1013
  MEL_RUN_ID: `assistant:${sid.split(":")[0]}`,
1014
+ // Span tracing → agents.spans. tracing_exporter.MelayaSpanExporter only
1015
+ // exports when BOTH MEL_RUN_ID and MEL_BUILDER_URL are present (it POSTs
1016
+ // batches through this same local relay the pipeline spawns use, lines
1017
+ // ~463/853). The assistant host was missing these two, so — even with
1018
+ // @trace_llm wired — every claude_code/codex assistant turn recorded ZERO
1019
+ // token spans. Spans land under conversation_id = MEL_RUN_ID
1020
+ // (`assistant:<userId>`); the server trigger resolves user_id from it.
1021
+ MEL_BUILDER_URL: `http://127.0.0.1:${relay.port}`,
1022
+ MEL_RELAY_NONCE: relay.nonce,
1014
1023
  MEL_PIPELINE_NAME: "Melaya · Assistant",
1015
1024
  // Luma browser bridge (same injection as pipeline runs, line ~431): lets
1016
1025
  // shared/tools/luma.py route /event/register through Playwright and bypass
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@melaya/runner",
3
- "version": "1.0.108",
3
+ "version": "1.0.110",
4
4
  "description": "Run Melaya AI pipelines locally with your own LM Studio or Ollama models",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,