fix(trigger): hide external trigger inputs

This commit is contained in:
chengyongru
2026-07-02 13:32:46 +08:00
committed by Xubin Ren
parent b690a48336
commit 55b550ee01
14 changed files with 327 additions and 40 deletions
+30 -18
View File
@@ -5,16 +5,43 @@ from __future__ import annotations
from typing import Any, Mapping
from nanobot.cron.types import CronJob
from nanobot.session.automation_turns import (
AutomationTurnSpec,
automation_history_overrides_for_spec,
automation_trigger,
)
CRON_TRIGGER_META = "_cron_trigger"
CRON_DEFER_UNTIL_IDLE_META = "_cron_defer_until_session_idle"
CRON_HISTORY_META = "_cron_turn"
def _cron_history_text(trigger: Mapping[str, Any]) -> str | None:
persist_content = trigger.get("persist_content")
return (
persist_content
if isinstance(persist_content, str) and persist_content.strip()
else None
)
CRON_AUTOMATION_SPEC = AutomationTurnSpec(
kind="cron",
trigger_meta_key=CRON_TRIGGER_META,
legacy_history_meta_key=CRON_HISTORY_META,
history_fields={
"cron_job_id": "job_id",
"cron_job_name": "job_name",
"cron_run_id": "run_id",
"cron_prompt_ref": "prompt_ref",
},
text_builder=_cron_history_text,
)
def cron_trigger(metadata: Mapping[str, Any] | None) -> dict[str, Any] | None:
"""Return structured cron trigger metadata when present."""
raw = (metadata or {}).get(CRON_TRIGGER_META)
return raw if isinstance(raw, dict) else None
return automation_trigger(metadata, CRON_AUTOMATION_SPEC)
def is_cron_turn(metadata: Mapping[str, Any] | None) -> bool:
@@ -38,22 +65,7 @@ def cron_run_id(metadata: Mapping[str, Any] | None) -> str | None:
def cron_history_overrides(metadata: Mapping[str, Any] | None) -> tuple[str | None, dict[str, Any]]:
"""Return session-history text/metadata overrides for a cron turn."""
trigger = cron_trigger(metadata)
if not trigger:
return None, {}
persist_content = trigger.get("persist_content")
text = (
persist_content
if isinstance(persist_content, str) and persist_content.strip()
else None
)
return text, {
CRON_HISTORY_META: True,
"cron_job_id": trigger.get("job_id"),
"cron_job_name": trigger.get("job_name"),
"cron_run_id": trigger.get("run_id"),
"cron_prompt_ref": trigger.get("prompt_ref"),
}
return automation_history_overrides_for_spec(metadata, CRON_AUTOMATION_SPEC)
def is_bound_cron_job(job: CronJob) -> bool: