summaryrefslogtreecommitdiffhomepage
path: root/packages/frontend/src/lib
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/frontend/src/lib
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/frontend/src/lib')
-rw-r--r--packages/frontend/src/lib/components/ToolPermissions.svelte6
-rw-r--r--packages/frontend/src/lib/settings.svelte.ts2
2 files changed, 8 insertions, 0 deletions
diff --git a/packages/frontend/src/lib/components/ToolPermissions.svelte b/packages/frontend/src/lib/components/ToolPermissions.svelte
index 6b09a07..4298724 100644
--- a/packages/frontend/src/lib/components/ToolPermissions.svelte
+++ b/packages/frontend/src/lib/components/ToolPermissions.svelte
@@ -53,6 +53,12 @@ const toolPermissions: ToolPermission[] = [
description: "Allow the AI to search the codebase with the cs ranked code-search engine",
},
{
+ id: "key_usage",
+ label: "Key usage",
+ description:
+ "Allow the AI to read current API-key usage levels, rate-limit headroom, and reset times",
+ },
+ {
id: "lsp",
label: "LSP queries",
description:
diff --git a/packages/frontend/src/lib/settings.svelte.ts b/packages/frontend/src/lib/settings.svelte.ts
index 0da4e45..1b93804 100644
--- a/packages/frontend/src/lib/settings.svelte.ts
+++ b/packages/frontend/src/lib/settings.svelte.ts
@@ -15,6 +15,7 @@ let toolPerms = $state<Record<string, boolean>>({
web_search: false,
youtube_transcribe: false,
search_code: false,
+ key_usage: false,
lsp: false,
});
let savedToolPerms = $state<Record<string, boolean>>({
@@ -29,6 +30,7 @@ let savedToolPerms = $state<Record<string, boolean>>({
web_search: false,
youtube_transcribe: false,
search_code: false,
+ key_usage: false,
lsp: false,
});
let skillChecks = $state<Record<string, boolean>>({});