a2a-source-edit: write agent.py
This commit is contained in:
13
agent.py
13
agent.py
@@ -30,6 +30,7 @@ from a2a_pack import (
|
||||
ASSET_TYPES = ("character", "enemy", "item", "tile", "icon", "projectile")
|
||||
STYLES = ("pixel", "flat", "outline", "neon")
|
||||
DB_OPTIONS = "-c statement_timeout=5000 -c lock_timeout=2000 -c idle_in_transaction_session_timeout=10000"
|
||||
DB_ENV_NAME = "DATABASE_URL"
|
||||
|
||||
|
||||
class GeneratesSvgVideoGame9jg9vdF0f510Config(BaseModel):
|
||||
@@ -90,7 +91,7 @@ class GeneratesSvgVideoGame9jg9vdF0f510(
|
||||
name="generates-svg-video-game-9jg9vd-f0f510-data",
|
||||
scope="user",
|
||||
access_mode="read_write",
|
||||
env=AgentDatabaseEnv(url="DATABASE_URL"),
|
||||
env=AgentDatabaseEnv(url=DB_ENV_NAME),
|
||||
migrations=AgentDatabaseMigrations(path="db/migrations"),
|
||||
),
|
||||
)
|
||||
@@ -170,7 +171,7 @@ class GeneratesSvgVideoGame9jg9vdF0f510(
|
||||
|
||||
warnings: list[str] = []
|
||||
persisted = False
|
||||
if os.environ.get("DATABASE_URL"):
|
||||
if os.environ.get(DB_ENV_NAME):
|
||||
try:
|
||||
_persist_asset_and_receipt(
|
||||
tenant_key=tenant,
|
||||
@@ -191,7 +192,7 @@ class GeneratesSvgVideoGame9jg9vdF0f510(
|
||||
except Exception as exc: # noqa: BLE001
|
||||
warnings.append(f"receipt persistence unavailable: {type(exc).__name__}")
|
||||
else:
|
||||
warnings.append("DATABASE_URL not configured; receipt persistence skipped in this environment")
|
||||
warnings.append("managed receipt store is not configured in this environment")
|
||||
|
||||
await ctx.emit_progress("svg asset generation complete")
|
||||
return SvgAssetResult(
|
||||
@@ -220,11 +221,11 @@ class GeneratesSvgVideoGame9jg9vdF0f510(
|
||||
limit: Annotated[int, Field(ge=1, le=25)] = 10,
|
||||
) -> ReceiptListResult:
|
||||
tenant = _tenant_key(ctx)
|
||||
if not os.environ.get("DATABASE_URL"):
|
||||
if not os.environ.get(DB_ENV_NAME):
|
||||
return ReceiptListResult(
|
||||
status="setup_required",
|
||||
receipts=[],
|
||||
warning="DATABASE_URL is not configured for this environment.",
|
||||
warning="Managed receipt storage is not configured for this environment.",
|
||||
)
|
||||
rows = _load_recent_receipts(tenant, limit)
|
||||
return ReceiptListResult(status="ok", receipts=[ReceiptSummary(**row) for row in rows])
|
||||
@@ -242,7 +243,7 @@ def _tenant_key(ctx: RunContext[PlatformUserAuth]) -> str:
|
||||
def _db_connection() -> Iterator[Any]:
|
||||
import psycopg
|
||||
|
||||
database_url = os.environ["DATABASE_URL"]
|
||||
database_url = os.environ[DB_ENV_NAME]
|
||||
with psycopg.connect(database_url, options=DB_OPTIONS) as conn:
|
||||
yield conn
|
||||
|
||||
|
||||
Reference in New Issue
Block a user