@@ -196,10 +196,18 @@ def _row_to_token_payload(cls, row: sqlite3.Row) -> dict[str, Any]:
196196 remaining = row [f"{ mode } _remaining" ]
197197 total = row [f"{ mode } _total" ]
198198 if always_include or remaining is not None or total is not None :
199- quota [ mode ] = {
199+ item = {
200200 "remaining" : cls ._payload_int (remaining ),
201201 "total" : cls ._payload_int (total ),
202202 }
203+ if mode == "console" :
204+ reset_at = cls ._payload_int (row ["console_reset_at" ])
205+ source = cls ._payload_int (row ["console_source" ])
206+ if reset_at > 0 :
207+ item ["reset_at" ] = reset_at
208+ if source in (0 , 1 , 2 ):
209+ item ["source" ] = source
210+ quota [mode ] = item
203211
204212 return {
205213 "token" : row ["token" ],
@@ -210,6 +218,9 @@ def _row_to_token_payload(cls, row: sqlite3.Row) -> dict[str, Any]:
210218 "fail_count" : cls ._payload_int (row ["usage_fail_count" ]),
211219 "last_used_at" : row ["last_use_at" ],
212220 "tags" : cls ._parse_tags (row ["tags" ]),
221+ "refresh_status" : str (row ["refresh_status" ] or "" ),
222+ "refresh_at" : row ["refresh_at" ],
223+ "refresh_error" : str (row ["refresh_error" ] or "" )[:300 ],
213224 }
214225
215226 def _upsert_sync (
@@ -578,6 +589,20 @@ def _token_payload_select_sql(cls) -> str:
578589 f"THEN json_extract({ column } , '$.total') END AS { mode } _total"
579590 for mode , column , _always_include in _TOKEN_PAYLOAD_QUOTAS
580591 )
592+ console_metadata_select = (
593+ "CASE WHEN json_valid(quota_console) "
594+ "THEN json_extract(quota_console, '$.reset_at') END AS console_reset_at, "
595+ "CASE WHEN json_valid(quota_console) "
596+ "THEN json_extract(quota_console, '$.source') END AS console_source"
597+ )
598+ refresh_metadata_select = (
599+ "CASE WHEN json_valid(ext) "
600+ "THEN json_extract(ext, '$.refresh_status') END AS refresh_status, "
601+ "CASE WHEN json_valid(ext) "
602+ "THEN json_extract(ext, '$.refresh_at') END AS refresh_at, "
603+ "CASE WHEN json_valid(ext) "
604+ "THEN json_extract(ext, '$.refresh_error') END AS refresh_error"
605+ )
581606 return f"""
582607 SELECT
583608 token,
@@ -587,7 +612,9 @@ def _token_payload_select_sql(cls) -> str:
587612 usage_use_count,
588613 usage_fail_count,
589614 last_use_at,
590- { quota_select }
615+ { quota_select } ,
616+ { console_metadata_select } ,
617+ { refresh_metadata_select }
591618 FROM { _TBL }
592619 WHERE deleted_at IS NULL
593620 ORDER BY updated_at DESC
0 commit comments