- scripts/trigger_gmail_scout.py: manually fire ScoutEngine.trigger_scout - scripts/inspect_gmail_scout_token.py: decrypt + show stored OAuth scopes - scripts/show_gmail_scout_state.py: print scout config + queue/log counts - scripts/reset_triage_queue_to_queued.py: revert delivered → queued for re-delivery - engine.py: info logs around deliver_pending (rows found, send_json roundtrip) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
75 lines
2.3 KiB
Python
75 lines
2.3 KiB
Python
"""Manually trigger the user's Gmail scout for testing.
|
|
|
|
Usage:
|
|
python scripts/trigger_gmail_scout.py [user_email]
|
|
|
|
If user_email omitted, picks the first user with a Gmail scout.
|
|
Runs ScoutEngine.trigger_scout — which calls Gmail history.list since last
|
|
gmail_history_id, fetches each new message, runs LLM triage, inserts queue rows
|
|
for relevant items.
|
|
|
|
After running, check the queue:
|
|
psql -d adiuvai -c "select source_msg_ref, triage_verdict, status from scout_triage_queue order by triaged_at desc limit 10"
|
|
|
|
Then restart the Electron app to trigger deliver_pending → frames → local
|
|
scout_suggestions rows.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import asyncio
|
|
import sys
|
|
import uuid
|
|
from pathlib import Path
|
|
|
|
# Ensure api/ root is importable when running from scripts/ subdir
|
|
_API_ROOT = Path(__file__).resolve().parent.parent
|
|
if str(_API_ROOT) not in sys.path:
|
|
sys.path.insert(0, str(_API_ROOT))
|
|
|
|
from sqlalchemy import select
|
|
|
|
from app.db import async_session
|
|
from app.models import CloudScoutConfig, User
|
|
from app.scouts.connectors.gmail import GmailConnector
|
|
from app.scouts.connectors.registry import register_connector
|
|
from app.scouts.engine import ScoutEngine
|
|
|
|
|
|
async def main() -> None:
|
|
register_connector(GmailConnector())
|
|
|
|
target_email = sys.argv[1] if len(sys.argv) > 1 else None
|
|
|
|
async with async_session() as session:
|
|
q = select(CloudScoutConfig).where(
|
|
CloudScoutConfig.provider == "gmail",
|
|
CloudScoutConfig.enabled.is_(True),
|
|
)
|
|
if target_email:
|
|
user = (
|
|
await session.execute(select(User).where(User.email == target_email))
|
|
).scalar_one_or_none()
|
|
if user is None:
|
|
print(f"No user with email {target_email}")
|
|
return
|
|
q = q.where(CloudScoutConfig.user_id == user.id)
|
|
|
|
scouts = (await session.execute(q)).scalars().all()
|
|
|
|
if not scouts:
|
|
print("No enabled Gmail scouts found. Create one in Settings → Scouts first.")
|
|
return
|
|
|
|
for scout in scouts:
|
|
print(f"Triggering scout id={scout.id} name={scout.name!r} user={scout.user_id}")
|
|
try:
|
|
await ScoutEngine().trigger_scout(uuid.UUID(scout.id))
|
|
print(" → done")
|
|
except Exception as exc:
|
|
print(f" → failed: {exc}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|