Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

feat(marketplace): expose token expires_at/last_refreshed in /plugins payload

Ruben Lütke17ac9f8ebb90
diff --git a/jarvis/ui/web/marketplace_routes.py b/jarvis/ui/web/marketplace_routes.py
index 9a57bc864f..967dfc78ec 100644
--- a/jarvis/ui/web/marketplace_routes.py
+++ b/jarvis/ui/web/marketplace_routes.py
@@ -80,16 +80,30 @@ def _refresh_plugin_in_live_registry(plugin_id: str) -> None:
# ----------------------------------------------------------------------
-def _plugin_status(plugin_id: str, store: TokenStore) -> str:
+def _plugin_status_meta(
+ plugin_id: str, store: TokenStore
+) -> tuple[str, str | None, str | None]:
+ """Return ``(status, expires_at_iso, last_refreshed_iso)`` from ONE token load.
+
+ ``expires_at`` / ``last_refreshed`` are surfaced so the UI can show an honest
+ "auto-refreshing / expiring soon" hint without re-deriving it. Both are
+ ``None`` for a token that carries no expiry (e.g. a PAT) or was never
+ refreshed — never a fabricated timestamp.
+ """
try:
tokens = store.load(plugin_id)
except RuntimeError:
- return "error"
+ return "error", None, None
if tokens is None:
- return "not_connected"
- if tokens.needs_reauth:
- return "needs_reauth"
- return "connected"
+ return "not_connected", None, None
+ expires_at = tokens.expires_at.isoformat() if tokens.expires_at else None
+ last_refreshed = tokens.extra.get("last_refreshed") or None
+ status = "needs_reauth" if tokens.needs_reauth else "connected"
+ return status, expires_at, last_refreshed
+
+
+def _plugin_status(plugin_id: str, store: TokenStore) -> str:
+ return _plugin_status_meta(plugin_id, store)[0]
def _build_dcr_handler(plugin_id: str, auth: HostedMcpOAuthDcrAuth) -> HostedMcpDcrHandler:
@@ -180,8 +194,10 @@ async def list_plugins(response: Response) -> dict[str, Any]:
connected = 0
for spec in catalog.plugins:
item = spec.model_dump(mode="json")
- status = _plugin_status(spec.id, store)
+ status, expires_at, last_refreshed = _plugin_status_meta(spec.id, store)
item["status"] = status
+ item["expires_at"] = expires_at
+ item["last_refreshed"] = last_refreshed
mcp = spec.mcp_server or {}
mcp_live, runtime_missing = _mcp_live(mcp)
if runtime_missing:
diff --git a/tests/unit/marketplace/test_plugin_status.py b/tests/unit/marketplace/test_plugin_status.py
index ce6d9060cf..9c126e8ece 100644
--- a/tests/unit/marketplace/test_plugin_status.py
+++ b/tests/unit/marketplace/test_plugin_status.py
@@ -78,3 +78,75 @@ async def test_list_plugins_marks_native_tool_as_live_callable(monkeypatch):
assert payload["plugins"][0]["status"] == "connected"
assert payload["plugins"][0]["live_callable"] is True
+
+
+def _gmail_catalog():
+ from jarvis.marketplace.catalog import PluginCatalog, PluginSpec
+
+ return PluginCatalog(
+ version=1,
+ schema_version="test",
+ plugins=[
+ PluginSpec(
+ id="gmail",
+ display_name="Gmail",
+ description="Mail",
+ category="Communication",
+ logo_slug="gmail",
+ native_tool="gmail",
+ auth={
+ "mode": "oauth_pkce_loopback",
+ "authorization_url": "https://accounts.example/auth",
+ "token_url": "https://accounts.example/token",
+ "client_id": "cid",
+ "scopes": ["scope"],
+ },
+ )
+ ],
+ )
+
+
+async def test_list_plugins_exposes_token_expiry_meta(monkeypatch):
+ """The payload surfaces expires_at + last_refreshed so the UI can show an
+ honest 'auto-refreshing / expiring soon' hint without re-deriving it."""
+ from datetime import datetime, timezone
+
+ from fastapi import Response
+
+ from jarvis.ui.web import marketplace_routes
+
+ exp = datetime(2026, 7, 1, 12, 0, tzinfo=timezone.utc)
+ store = TokenStore(InMemoryBackend())
+ store.save(
+ "gmail",
+ Tokens(
+ access="tok",
+ expires_at=exp,
+ extra={"last_refreshed": "2026-06-30T10:00:00+00:00"},
+ ),
+ )
+ monkeypatch.setattr(marketplace_routes, "load_catalog", _gmail_catalog)
+ monkeypatch.setattr(marketplace_routes, "TokenStore", lambda: store)
+
+ item = (await marketplace_routes.list_plugins(Response()))["plugins"][0]
+ assert item["expires_at"] == exp.isoformat()
+ assert item["last_refreshed"] == "2026-06-30T10:00:00+00:00"
+
+
+async def test_list_plugins_omits_expiry_meta_when_absent(monkeypatch):
+ """A token with no expiry / never-refreshed (e.g. a PAT) carries null meta,
+ never a fabricated timestamp."""
+ from fastapi import Response
+
+ from jarvis.ui.web import marketplace_routes
+
+ store = TokenStore(InMemoryBackend())
+ store.save("gmail", Tokens(access="tok"))
+ monkeypatch.setattr(marketplace_routes, "load_catalog", _gmail_catalog)
+ monkeypatch.setattr(marketplace_routes, "TokenStore", lambda: store)
+
+ item = (await marketplace_routes.list_plugins(Response()))["plugins"][0]
+ assert item["expires_at"] is None
+ assert item["last_refreshed"] is None