diff --git a/agent.py b/agent.py index f05ad3f..32083a0 100644 --- a/agent.py +++ b/agent.py @@ -14,7 +14,6 @@ import io import json import os import re -import time from datetime import UTC, datetime from typing import Annotated, Any @@ -98,7 +97,7 @@ class QuoteJudgeStudioV1(A2AAgent[QuoteJudgeStudioV1Config, PlatformUserAuth]): "and warranty scoring, persists results, supports bounded uploads, and " "exposes typed MCP-compatible A2A tools." ) - version = "0.1.0" + version = "0.1.1" config_model = QuoteJudgeStudioV1Config auth_model = PlatformUserAuth @@ -653,20 +652,30 @@ def _ensure_schema(conn: Any) -> None: """ CREATE TABLE IF NOT EXISTS quote_judge_receipts ( id BIGSERIAL PRIMARY KEY, + receipt_id TEXT, tenant_key TEXT NOT NULL, comparison_id TEXT, - skill_name TEXT NOT NULL, - receipt_json JSONB NOT NULL, + skill_name TEXT, + tool_name TEXT, + status TEXT, + input_hash TEXT, + result_hash TEXT, + receipt_json JSONB, + payload JSONB, created_at TIMESTAMPTZ NOT NULL DEFAULT NOW() ) """ ) - conn.execute( - "CREATE INDEX IF NOT EXISTS app_records_tenant_kind_idx ON app_records (tenant_key, record_kind, created_at DESC)" - ) - conn.execute( - "CREATE INDEX IF NOT EXISTS quote_judge_receipts_tenant_idx ON quote_judge_receipts (tenant_key, created_at DESC)" - ) + conn.execute("ALTER TABLE quote_judge_receipts ADD COLUMN IF NOT EXISTS receipt_id TEXT") + conn.execute("ALTER TABLE quote_judge_receipts ADD COLUMN IF NOT EXISTS skill_name TEXT") + conn.execute("ALTER TABLE quote_judge_receipts ADD COLUMN IF NOT EXISTS tool_name TEXT") + conn.execute("ALTER TABLE quote_judge_receipts ADD COLUMN IF NOT EXISTS status TEXT") + conn.execute("ALTER TABLE quote_judge_receipts ADD COLUMN IF NOT EXISTS input_hash TEXT") + conn.execute("ALTER TABLE quote_judge_receipts ADD COLUMN IF NOT EXISTS result_hash TEXT") + conn.execute("ALTER TABLE quote_judge_receipts ADD COLUMN IF NOT EXISTS receipt_json JSONB") + conn.execute("ALTER TABLE quote_judge_receipts ADD COLUMN IF NOT EXISTS payload JSONB") + conn.execute("CREATE INDEX IF NOT EXISTS app_records_tenant_kind_idx ON app_records (tenant_key, record_kind, created_at DESC)") + conn.execute("CREATE INDEX IF NOT EXISTS quote_judge_receipts_tenant_idx ON quote_judge_receipts (tenant_key, created_at DESC)") def _load_legacy_comparison(conn: Any, tenant: str, comparison_id: str) -> dict[str, Any] | None: @@ -710,6 +719,7 @@ async def _persist_receipt( "agent": QuoteJudgeStudioV1.name, "agent_version": QuoteJudgeStudioV1.version, "skill_name": skill_name, + "tool_name": skill_name, "comparison_id": comparison_id, "tenant_scope": "user", "task_id": getattr(ctx, "task_id", ""), @@ -732,10 +742,22 @@ async def _persist_receipt( conn.execute( """ INSERT INTO quote_judge_receipts - (tenant_key, comparison_id, skill_name, receipt_json) - VALUES (%s, %s, %s, %s) + (receipt_id, tenant_key, comparison_id, skill_name, tool_name, + status, input_hash, result_hash, receipt_json, payload) + VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s) """, - (tenant, comparison_id or None, skill_name, Jsonb(receipt)), + ( + receipt["receipt_id"], + tenant, + comparison_id or None, + skill_name, + skill_name, + receipt["status"], + receipt["input_hash"], + receipt["result_hash"], + Jsonb(receipt), + Jsonb(receipt), + ), ) return {"persisted": True, "receipt_id": receipt["receipt_id"]} except Exception: # noqa: BLE001