Skip to content

armgit / kwant

Public Imported from GitHub
0

Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.

Settings: "needs you" counts only accounts bots rely on (accounts-needs-only-used) (#908)

Oleksandr Ivanchenko01c277b52ab9
diff --git a/frontend/src/appsAccounts.ts b/frontend/src/appsAccounts.ts
index 7c7c5ff1..fe1fed85 100644
--- a/frontend/src/appsAccounts.ts
+++ b/frontend/src/appsAccounts.ts
@@ -85,6 +85,25 @@ const BAD = new Set(['needs_sign_in', 'error', 'limited', 'locked']);
export const accountNeedsYou = (c: Pick<Connection, 'kind' | 'status' | 'used_by'>): boolean =>
c.kind === 'account' && BAD.has(c.status) && c.used_by.length > 0;
+/**
+ * How many AI accounts the header's amber "needs you" counts (31a). The server lists every auto bot on each
+ * engine's main account, so `accountNeedsYou` alone also flags a signed-out account the panel shows under
+ * Not used. An account counts only when a bot really relies on it: it's in the used list (`usedIds`, as
+ * `accountGroups` splits it) and broken, or a bot is pinned to it (`pinnedIds`: it can't fail over), or
+ * nothing is used at all, when every broken account is worth the amber since no bot can run.
+ * Ids are profile ids; connections are `account:<profile id>`.
+ */
+export function accountsNeedingYou(connections: Array<Pick<Connection, 'id' | 'kind' | 'status' | 'used_by'>>, usedIds: string[], pinnedIds: string[]): number {
+ const used = new Set(usedIds);
+ const pinned = new Set(pinnedIds);
+ return connections.filter((c) => {
+ if (!accountNeedsYou(c)) return false;
+ if (!used.size) return true;
+ const id = c.id.startsWith('account:') ? c.id.slice(8) : c.id;
+ return used.has(id) || pinned.has(id);
+ }).length;
+}
+
// ── Giving the Composio server to the chosen bots ────────────────────────────────────────────
/** The MCP server id inside a connection id (`mcp:<id>`). */
diff --git a/frontend/src/components/AppsAccounts.tsx b/frontend/src/components/AppsAccounts.tsx
index 20aaa0b6..3586ea1b 100644
--- a/frontend/src/components/AppsAccounts.tsx
+++ b/frontend/src/components/AppsAccounts.tsx
@@ -12,7 +12,7 @@ import {
AppTile,
AppsSection,
GiveError,
- accountNeedsYou,
+ accountsNeedingYou,
appInitials,
approvalLine,
botsWithServer,
@@ -26,6 +26,7 @@ import { useEscapeLayer } from '../escape';
import { ProfilesState, useProfiles } from '../useProfiles';
import { EnginesApi, useEngines } from '../useEngines';
import { parsePick, type EngineInfo } from '../engines';
+import { accountGroups, failoverOrder } from '../failover';
import { AccountPriority } from './AccountPriority';
import { Profile, cardOf } from '../profiles';
import type { Kwant } from './Sidebar';
@@ -574,7 +575,10 @@ export const AppsAccounts: React.FC<AppsAccountsProps> = (p) => {
return !pinnedOnly || !bot || parsePick(bot.preferred_model).family !== 'auto';
})
.map((u) => u.name);
- const needs = data ? data.connections.filter((c) => accountNeedsYou(c)).length : 0;
+ // Only accounts a bot relies on: used and broken, pinned, or anything broken when nothing is used (31a).
+ const usedIds = profiles ? accountGroups(failoverOrder(profiles), (a) => engines?.find((e) => e.id === cardOf(a))).used.map((a) => a.id) : [];
+ const pinnedIds = (profiles ?? []).filter((a) => usedByOf(a.id, true).length > 0).map((a) => a.id);
+ const needs = data ? accountsNeedingYou(data.connections, usedIds, pinnedIds) : 0;
/** Opens "Sign-ins and settings", at one AI's card when given: its existing sign-in or set-up. */
const afterRender = useAfterRender();
const openManage = (engineCard?: string) => {
diff --git a/frontend/tests/appsAccounts.test.mjs b/frontend/tests/appsAccounts.test.mjs
index d6aa2317..42a692f4 100644
--- a/frontend/tests/appsAccounts.test.mjs
+++ b/frontend/tests/appsAccounts.test.mjs
@@ -344,6 +344,32 @@ test('opening at Advanced shows it; a used account that can’t run counts as ne
assert.match(html, /data-ai-needs[^>]*>1 needs you/);
});
+// 31a (Mira's UX pass on 0.9.31, fix 3): the amber counts only accounts the panel shows bots relying on.
+const auto = [{ id: 'k1', name: 'Ann' }, { id: 'k2', name: 'Ben' }];
+test('accountsNeedingYou: a signed-out account under Not used never counts, unless a bot is pinned to it or nothing is used', () => {
+ const claude = acct('sys', { used_by: auto });
+ const codex = acct('p2', { name: 'Work', detail: 'codex', status: 'needs_sign_in', used_by: auto });
+ // Mira's state: Claude ready and used, Codex signed out with every auto bot in used_by, nobody pinned.
+ assert.equal(m.accountsNeedingYou([claude, codex], ['sys'], []), 0);
+ // A bot pinned to Codex can't fail over: that's a real ask.
+ assert.equal(m.accountsNeedingYou([claude, codex], ['sys'], ['p2']), 1);
+ // The account bots run on is still ranked but out of usage.
+ assert.equal(m.accountsNeedingYou([acct('sys', { status: 'limited', used_by: auto }), codex], ['sys'], []), 1);
+ // Nothing is used at all: every bad account is worth the amber.
+ assert.equal(m.accountsNeedingYou([acct('sys', { status: 'needs_sign_in', used_by: auto }), codex], [], []), 2);
+ // Unused (nobody in used_by) stays quiet, whatever the order says.
+ assert.equal(m.accountsNeedingYou([acct('p3', { status: 'error' })], [], ['p3']), 0);
+});
+
+test('Settings in Mira’s state shows no amber; with a bot pinned to the signed-out Codex it says 1 needs you', () => {
+ const conns = [acct('sys', { used_by: auto }), acct('p2', { name: 'Work', detail: 'codex', status: 'needs_sign_in', used_by: auto })];
+ const calm = m.renderToStaticMarkup(h(m.AppsAccounts, pageProps({ data: data({ connections: conns }) })));
+ assert.ok(!calm.includes('data-ai-needs'), 'Codex is Not used: no "needs you"');
+ const pinned = bots.map((b, i) => (i === 0 ? { ...b, preferred_model: 'codex' } : b));
+ const ask = m.renderToStaticMarkup(h(m.AppsAccounts, pageProps({ kwants: pinned, data: data({ connections: conns }) })));
+ assert.match(ask, /data-ai-needs[^>]*>1 needs you/);
+});
+
test('Advanced’s Composio card offers Choose bots instead of Turn on in Tools, and leaves AI accounts out', () => {
const html = m.renderToStaticMarkup(
h(m.ConnectionsView, {