UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

18 lines (17 loc) • 1.04 kB
import { openSystemReminder } from "../../core/reminder-mint.js"; const GH_COMMAND_RE = /(?:^|[;&|]|\b(?:then|do)\b)\s*gh\s+(?!auth\b|help\b|version\b|alias\b|completion\b|config\b)/; const RATE_LIMITED_RE = /API rate limit (?:already )?exceeded|exceeded a secondary rate limit|\bRATE_LIMITED\b/i; const THROTTLE_MS = 60_000; let nextHintAt = 0; export function resetGhRateLimitHintThrottleForTests() { nextHintAt = 0; } export function ghRateLimitHint(command, output, now = Date.now(), monitorToolActive, mark) { if (!GH_COMMAND_RE.test(command) || !RATE_LIMITED_RE.test(output) || now < nextHintAt) return undefined; nextHintAt = now + THROTTLE_MS; return (`${openSystemReminder(mark)}GitHub API rate limit exceeded (5,000/hr shared across all tools and agents). ` + "Run `gh api rate_limit --jq .resources` and sleep until reset before further gh calls." + (monitorToolActive !== false ? " If polling in a loop, use the Monitor tool instead of retrying." : "") + "</system-reminder>"); }