"""Job entrypoint: run the Gumbo LangGraph once and print the summary to stdout."""

from __future__ import annotations

import asyncio
import json
import os
import sys

from gumbo.graph import run_gumbo


async def _main() -> int:
    object_key = os.environ["GUMBO_OBJECT_KEY"]
    thread_id = os.environ.get("GUMBO_THREAD_ID", "gumbo-default-thread")
    conn = os.environ["LANGGRAPH_CHECKPOINT_URI"]

    result = await run_gumbo(object_key, thread_id, conn)
    payload = {"summary": result["summary"], "object_key": object_key, "thread_id": thread_id}
    sys.stdout.write(json.dumps(payload))
    sys.stdout.flush()
    return 0


def main() -> None:
    raise SystemExit(asyncio.run(_main()))


if __name__ == "__main__":
    main()
