mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 12:07:28 +01:00
* feat(providers): one-tap switch to a provider that still has quota When the agent building a project hits a rate limit, the way out already existed — four other agent CLIs, most with untouched quota. Taking it was the problem. The only chooser lived in the Terminal right rail, it offered every agent in a fixed order whether or not the connected builder had it installed, and taking it swapped the live PTY without recording the choice, so the next dispatch went straight back to the agent that had just run out. One ranking, three surfaces: - src/lib/provider-switch.ts — the whole decision as pure functions. Ranks the operator's order, filters on two pieces of OBSERVED evidence (the builder's installed-agent report, and recent runs that died with capacity language), and holds the three-state rule provider_quota is built on: an agent nothing was reported about is unknown, and unknown reads as usable. Nothing is hidden — a provider that cannot answer still appears, disabled, saying why. 18 inline checks in scripts/test/provider-switch.ts. - GET /api/providers — that ranking, once, for every surface. Accepts either the user_projects id or the entity id, because the Feedback row holds one and Control/Terminal hold the other. - ProviderSwitch — "Try <next>" plus a menu of the rest, now the PRIMARY control on a Needs-you / Failed feedback row (Retry steps down beside it), in the Control inbox, and in the Terminal rail. And it sticks: POST /api/feedback/<id>/dispatch takes an `agent`, records it as the project's agentPref, then dispatches on it — no scavenger hunt through project settings. The order is the operator's, not the fleet's: user_preferences.agent_order (migration 0072, nullable and additive) with a reorder list in Settings → Agent. Null means "never stated", and the fleet default applies. Two SSOT repairs the work ran into: - AGENT_FALLBACK_ORDER was defined TWICE (agent-registry.ts and agent-resolution.ts) — the server reroute and the client reroute each read their own copy. agent-registry now re-exports the client-safe leaf. - QUOTA_ALTERNATIVE_AGENTS is derived from that order instead of being a second hand-written list of the same five ids. - TerminalRunView.alternatives is gone; quotaDeath stays as the flag that asks the shared chooser. provider_quota is deliberately NOT an input: it meters the ai-kit inference chain (groq, openrouter) behind Loki's own chat, not the agent CLIs. The agent-CLI equivalent is the run evidence above — observed, never probed. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix(providers): never offer the agent the project would actually run on Self-review caught a gap in the chooser's exclusion rule. It read "current" straight off `user_projects.agent_pref`, so a project that has never had a preference set reported no current agent at all — and dispatch does not work that way. Such a project still runs, on DEFAULT_ADAPTER_ID, which means the escape offered from a Claude Code rate limit could be Claude Code. currentProviderFor() answers the question the exclusion is actually asking — which agent just died — in the order the evidence deserves: 1. what this project LAST RAN on (freshest run inside the window). A stored preference can be stale by one switch; a run is what happened. 2. else its stored preference. 3. else the fleet default, because that is what the next dispatch picks. A run on an agent the chooser cannot offer (openclaw) is not "current" — it falls through rather than excluding nothing. Three more checks in scripts/test/provider-switch.ts, 21 total. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
22 lines
1.1 KiB
SQL
22 lines
1.1 KiB
SQL
-- Migration: user_preferences.agent_order — which provider to reach for next.
|
|
--
|
|
-- "Try next provider" needs an order, and until now the only one that existed
|
|
-- was AGENT_FALLBACK_ORDER, a constant in the source. So the button offered the
|
|
-- fleet's opinion rather than the operator's: it said "Try Cursor" to someone
|
|
-- whose Cursor subscription had lapsed, and the only way to express otherwise
|
|
-- was to set a per-project agent preference, one project at a time, after the
|
|
-- switch had already gone to the wrong place.
|
|
--
|
|
-- One ordered string, not a rank-per-agent table: the only question ever asked
|
|
-- of this column is "what is the whole order", and a list is how an ordered
|
|
-- list is spelled.
|
|
--
|
|
-- NULL is a real answer and not a missing one — it means the operator never
|
|
-- stated a preference, and the fleet default applies. Unknown ids inside the
|
|
-- string are dropped on read (parseProviderOrder), so a retired agent id in an
|
|
-- old row degrades to "not ranked" rather than breaking the chooser.
|
|
--
|
|
-- Nullable and additive. Every existing row keeps its meaning.
|
|
|
|
ALTER TABLE "user_preferences" ADD COLUMN IF NOT EXISTS "agent_order" text;
|