Version 1.2.2. Added usage overview. Shows token used and cost in $.

This commit is contained in:
2026-04-15 10:00:39 +02:00
parent 752691fe54
commit d4c6420481
18 changed files with 1657 additions and 86 deletions

View File

@@ -465,6 +465,29 @@ _MIGRATIONS: list[list[str]] = [
[
"ALTER TABLE webhook_targets ADD COLUMN IF NOT EXISTS owner_user_id TEXT REFERENCES users(id) ON DELETE CASCADE",
],
# v28 — Browser trusted domains (per-user interaction pre-approval)
[
"""
CREATE TABLE IF NOT EXISTS browser_approved_domains (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
owner_user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
domain TEXT NOT NULL,
note TEXT,
created_at TIMESTAMPTZ DEFAULT NOW(),
UNIQUE (owner_user_id, domain)
)
""",
],
# v29 — Track model per agent run for usage/cost overview
[
"ALTER TABLE agent_runs ADD COLUMN IF NOT EXISTS model TEXT",
],
# v30 — Track token usage and cost per chat conversation
[
"ALTER TABLE conversations ADD COLUMN IF NOT EXISTS input_tokens INTEGER NOT NULL DEFAULT 0",
"ALTER TABLE conversations ADD COLUMN IF NOT EXISTS output_tokens INTEGER NOT NULL DEFAULT 0",
"ALTER TABLE conversations ADD COLUMN IF NOT EXISTS cost_usd REAL",
],
]
@@ -821,7 +844,15 @@ filesystem_whitelist_store = FilesystemWhitelistStore()
# ─── Initialisation ───────────────────────────────────────────────────────────
async def _init_connection(conn: asyncpg.Connection) -> None:
"""Register codecs on every new connection so asyncpg handles JSONB ↔ dict."""
"""
Register codecs on every new connection so asyncpg handles JSONB ↔ dict automatically.
Critical: asyncpg does NOT auto-serialize Python dicts to PostgreSQL JSONB.
Without this, inserting a dict into a JSONB column raises:
asyncpg.exceptions.UnsupportedClientFeatureError: ...
The codecs must be registered on every connection (not just once on the pool),
which is why this is passed as `init=` to create_pool().
"""
await conn.set_type_codec(
"jsonb",
encoder=json.dumps,