feat: implement Trello authentication & connection plugin
Add TrelloClient for Trello REST API interaction with env-var-based credential management (TRELLO_API_KEY, TRELLO_TOKEN). Implements: - trello_verify_credentials — verify API key/token against Trello API - trello_list_boards — list accessible Trello boards - trello_disconnect — clear in-memory credentials Includes full test suite (18 tests), spec document, and plugin metadata. Issue: #1
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
"""
|
||||
Trello Plugin — Hermes Agent tool definitions.
|
||||
|
||||
Each function decorated with ``@tool`` registers itself as a Hermes tool
|
||||
that the agent can invoke during a conversation.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
from typing import Any
|
||||
|
||||
from trello_plugin.client import TrelloClient
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Module-level client (lazily initialised so env vars can be overridden)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
_client: TrelloClient | None = None
|
||||
|
||||
|
||||
def _get_client() -> TrelloClient:
|
||||
global _client # noqa: PLW0603
|
||||
api_key = os.environ.get("TRELLO_API_KEY", "")
|
||||
token = os.environ.get("TRELLO_TOKEN", "")
|
||||
if _client is None or _client.api_key != api_key or _client.token != token:
|
||||
_client = TrelloClient(api_key=api_key, token=token)
|
||||
return _client
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Tool helpers
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def _respond(data: dict[str, Any]) -> str:
|
||||
"""Wrap a result dict in a JSON string, the Hermes tool contract."""
|
||||
return json.dumps(data, indent=2)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Tools
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def trello_verify_credentials() -> str:
|
||||
"""Verify that the Trello API key and token are valid.
|
||||
|
||||
Checks the ``TRELLO_API_KEY`` and ``TRELLO_TOKEN`` environment variables
|
||||
and attempts a test call to the Trello API. Returns the authenticated
|
||||
user's Trello username on success.
|
||||
"""
|
||||
client = _get_client()
|
||||
result = client.verify_credentials()
|
||||
return _respond(result)
|
||||
|
||||
|
||||
def trello_list_boards() -> str:
|
||||
"""List all Trello boards accessible to the authenticated user.
|
||||
|
||||
Requires ``TRELLO_API_KEY`` and ``TRELLO_TOKEN`` to be set.
|
||||
Returns board id, name, URL, and whether the board is closed/starred.
|
||||
"""
|
||||
client = _get_client()
|
||||
result = client.list_boards()
|
||||
return _respond(result)
|
||||
|
||||
|
||||
def trello_disconnect() -> str:
|
||||
"""Disconnect from Trello by clearing credentials from memory.
|
||||
|
||||
This does NOT revoke the Trello token — invalidate it via
|
||||
Trello's account settings if full revocation is desired.
|
||||
"""
|
||||
global _client # noqa: PLW0603
|
||||
_client = None
|
||||
return _respond({"success": True, "message": "Trello credentials cleared. Reconnect by calling trello_verify_credentials after setting TRELLO_API_KEY and TRELLO_TOKEN."})
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Plugin metadata (used by Hermes plugin loader)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
PLUGIN_NAME = "trello-plugin"
|
||||
PLUGIN_DESCRIPTION = "Hermes Agent plugin for Trello board integration"
|
||||
PLUGIN_VERSION = "0.1.0"
|
||||
PLUGIN_TOOLS = [
|
||||
trello_verify_credentials,
|
||||
trello_list_boards,
|
||||
trello_disconnect,
|
||||
]
|
||||
PLUGIN_REQUIRES_ENV = ["TRELLO_API_KEY", "TRELLO_TOKEN"]
|
||||
|
||||
|
||||
def check_requirements() -> bool:
|
||||
"""Return True when both Trello env vars are present."""
|
||||
return TrelloClient.check_requirements()
|
||||
Reference in New Issue
Block a user