summaryrefslogtreecommitdiffhomepage
path: root/packages/core/src/tools/summon.ts
diff options
context:
space:
mode:
authorAdam Malczewski <[email protected]>2026-06-02 22:50:00 +0900
committerAdam Malczewski <[email protected]>2026-06-02 22:50:00 +0900
commitbb5ce098a99e4ea8f36c6a725290d5858c36460f (patch)
tree06920814d74f82dbaa6c8de420558ec48660e862 /packages/core/src/tools/summon.ts
parent4b45d33c256cf580a53054078be6fd7148fa6302 (diff)
downloaddispatch-bb5ce098a99e4ea8f36c6a725290d5858c36460f.tar.gz
dispatch-bb5ce098a99e4ea8f36c6a725290d5858c36460f.zip
feat(tools): add key_usage tool reporting API-key usage levels
Adds an agent-callable `key_usage` tool that reports current usage for configured API keys so the agent can pick a key with headroom, warn before hitting a rate limit, and diagnose exhausted-key failures. Per key it reports: provider, active/exhausted status (with last error + when it was exhausted), remaining rate-limit headroom and reset timestamp per window (5-hour, weekly, and monthly where the provider exposes it), and whether the figures are live or served from cache (with the cache's last-fetched-from-source time). Supports anthropic and opencode-go keys (live with cache fallback for anthropic; live scrape for opencode-go). Optional `key_id` reports one key; omitted reports all. Hard permission gate `perm_key_usage` (default off): when disabled the tool is completely removed from the toolset/context. Registered in both the parent permission-gated path and the child whitelist path, advertised in the system prompt (TOOL_DESCRIPTIONS), grantable to subagents via the summon enum, and exposed as a frontend tool-permission checkbox. To report data freshness, claude.ts gains `getAccountUsageWithSource` + `ClaudeUsageResult` (live vs cache + cachedAt from usage_cache.cached_at); the existing `getAccountUsage` now delegates to it, preserving behavior. Tests: core key-usage tool suite (windows, %-conversion, freshness, exhausted status, unsupported/unavailable, filtering) + agent-manager perm-gate test.
Diffstat (limited to 'packages/core/src/tools/summon.ts')
-rw-r--r--packages/core/src/tools/summon.ts1
1 files changed, 1 insertions, 0 deletions
diff --git a/packages/core/src/tools/summon.ts b/packages/core/src/tools/summon.ts
index b941152..2a076e6 100644
--- a/packages/core/src/tools/summon.ts
+++ b/packages/core/src/tools/summon.ts
@@ -287,6 +287,7 @@ export function createSummonTool(
"write_file",
"run_shell",
"search_code",
+ "key_usage",
"todo",
"summon",
"retrieve",