|
# retoor <retoor@molodetz.nl>
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
from typing import Any
|
|
|
|
from ..errors import ToolInputError
|
|
from .tracker import get_tracker
|
|
|
|
|
|
class CostController:
|
|
async def dispatch(self, name: str, arguments: dict[str, Any]) -> str:
|
|
if name != "cost_stats":
|
|
raise ToolInputError(f"Unknown cost tool: {name}")
|
|
tracker = get_tracker()
|
|
if tracker is None:
|
|
return json.dumps(
|
|
{"status": "unavailable", "message": "No cost tracker is active for this session."}
|
|
)
|
|
return json.dumps({"status": "success", **tracker.stats()}, ensure_ascii=False)
|