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.

No-account reply: setup_needed meta flag and a card that opens Space settings → Accounts

Lin (kwant bot)4c68ce4535bb
diff --git a/frontend/src/components/ChatView.tsx b/frontend/src/components/ChatView.tsx
index e822fb0c..56a961ce 100644
--- a/frontend/src/components/ChatView.tsx
+++ b/frontend/src/components/ChatView.tsx
@@ -31,6 +31,7 @@ import {
import { FileTiles, UploadChip } from './Attachments';
import { ranOnLabel } from '../engines';
import { parseRoutingMeta, ranOnAccount, routingLine } from '../spaces';
+import { SetupNeededCard, parseSetupMeta } from './SetupNeededCard';
export interface ChatMessage {
id: string;
@@ -160,6 +161,10 @@ export interface ChatViewProps {
renderBotAction?: (msg: ChatMessage, meta: BotActionMeta, flash: boolean) => React.ReactNode;
/** A bot's proposal to hire a new bot (message meta kind "hire_proposal"). */
renderHire?: (msg: ChatMessage, meta: HireMeta, flash: boolean) => React.ReactNode;
+ /** Opens Space settings → Accounts; turns a "nothing can run" reply into a card with a button. */
+ onOpenAccounts?: () => void;
+ /** Whether anything can run a bot in this space now (null while unknown). */
+ canRun?: boolean | null;
/** The open chat's turn is paused on a question: it is waiting for the person, not working. */
awaitingAnswer?: boolean;
/** Changes when another chat opens, so the view jumps to its bottom. */
@@ -310,6 +315,8 @@ export const ChatView: React.FC<ChatViewProps> = ({
renderMcpSuggestion,
renderBotAction,
renderHire,
+ onOpenAccounts,
+ canRun = null,
awaitingAnswer,
contextKey,
}) => {
@@ -652,6 +659,20 @@ export const ChatView: React.FC<ChatViewProps> = ({
if (botAction && renderBotAction) return <React.Fragment key={msg.id}>{renderBotAction(msg, botAction, flashId === msg.id)}</React.Fragment>;
const hire = msg.meta && renderHire ? parseHireMeta(msg.meta) : null;
if (hire && renderHire) return <React.Fragment key={msg.id}>{renderHire(msg, hire, flashId === msg.id)}</React.Fragment>;
+ const setup = msg.meta && onOpenAccounts ? parseSetupMeta(msg.meta) : null;
+ if (setup && onOpenAccounts)
+ return (
+ <div key={msg.id} data-message-id={msg.id} className="w-full max-w-5xl">
+ <SetupNeededCard
+ meta={setup}
+ botName={msg.sender_id || title}
+ spaceName={spaceName ?? 'this space'}
+ canRun={canRun}
+ onOpenAccounts={onOpenAccounts}
+ flash={flashId === msg.id}
+ />
+ </div>
+ );
const isUser = msg.sender_role === 'user';
const files = msg.meta ? parseAttachments(msg.meta) : [];
// A bot's share_file note: the file tiles say it all.
diff --git a/frontend/src/components/SetupNeededCard.tsx b/frontend/src/components/SetupNeededCard.tsx
new file mode 100644
index 00000000..d4f1129d
--- /dev/null
+++ b/frontend/src/components/SetupNeededCard.tsx
@@ -0,0 +1,65 @@
+import React from 'react';
+import { AlertTriangle, CheckCircle2, KeyRound } from 'lucide-react';
+import { parseMetaObject } from '../questions';
+
+/** A turn nothing could run (message meta kind `setup_needed`, from src/drivers/engines.rs). */
+export interface SetupMeta {
+ reason: 'no_account' | 'host_off';
+}
+
+export function parseSetupMeta(raw: unknown): SetupMeta | null {
+ const m = parseMetaObject(raw);
+ if (!m || m.kind !== 'setup_needed') return null;
+ return { reason: m.reason === 'host_off' ? 'host_off' : 'no_account' };
+}
+
+interface Props {
+ meta: SetupMeta;
+ botName: string;
+ spaceName: string;
+ /** Whether something can run now; once it can, the card says to send the message again. */
+ canRun: boolean | null;
+ onOpenAccounts: () => void;
+ flash?: boolean;
+}
+
+/** Shown in place of the bot's reply when no account could run its turn, with a way to fix it. */
+export const SetupNeededCard: React.FC<Props> = ({ meta, botName, spaceName, canRun, onOpenAccounts, flash }) => {
+ const fixed = canRun === true;
+ const detail = fixed
+ ? `An account works in ${spaceName} now. Send your message again to get a reply.`
+ : meta.reason === 'host_off'
+ ? `This machine is off in ${spaceName} and no other account is on. Turn one on, or add an account.`
+ : `No account can run bots in ${spaceName} yet. Sign in with Claude, Codex or Grok, or add an API key.`;
+ return (
+ <div className={`flex items-start gap-3.5 w-full max-w-5xl rounded-xl ${flash ? 'kw-flash' : ''}`} data-setup-card={meta.reason}>
+ <div
+ className={`w-[34px] h-[34px] flex-shrink-0 rounded-full flex items-center justify-center border ${
+ fixed ? 'bg-emerald-500/10 border-emerald-500/40' : 'bg-amber-500/10 border-amber-500/40'
+ }`}
+ aria-hidden="true"
+ >
+ {fixed ? <CheckCircle2 size={16} className="text-emerald-300" /> : <AlertTriangle size={16} className="text-amber-300" />}
+ </div>
+ <div
+ role="status"
+ className={`min-w-0 flex-1 max-w-xl rounded-2xl rounded-tl-sm border p-4 ${
+ fixed ? 'border-zinc-800 bg-zinc-900/60' : 'border-amber-500/30 bg-amber-500/5'
+ }`}
+ >
+ <p className="text-sm font-medium text-zinc-100">{fixed ? `${botName} can answer now` : `${botName} can't answer yet`}</p>
+ <p className="mt-1 text-xs text-zinc-400 leading-relaxed">{detail}</p>
+ {!fixed && (
+ <button
+ type="button"
+ onClick={onOpenAccounts}
+ className="mt-3 inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium text-white bg-sky-600 hover:bg-sky-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-sky-300"
+ >
+ <KeyRound size={13} aria-hidden="true" />
+ Add an account
+ </button>
+ )}
+ </div>
+ </div>
+ );
+};
diff --git a/frontend/src/engines.ts b/frontend/src/engines.ts
index c3ba3971..6d10a7df 100644
--- a/frontend/src/engines.ts
+++ b/frontend/src/engines.ts
@@ -61,6 +61,14 @@ export type Tone = 'ok' | 'warn' | 'error' | 'muted' | 'busy' | 'info';
/** Whether kwants can run on it: the server's `ready` (which counts its accounts), else the host check. */
export const isUsable = (e: Pick<EngineInfo, 'status' | 'enabled' | 'ready'>) => e.enabled !== false && (e.ready ?? e.status === 'ready');
+/** Whether anything can run a bot in the space: null while unknown (not loaded, or still
+ * checking with nothing ready yet), so "nothing can run" never flashes during startup checks. */
+export function canRunNow(engines: EngineInfo[] | null | undefined): boolean | null {
+ if (!engines?.length) return null;
+ if (engines.some(isUsable)) return true;
+ return engines.some((e) => e.enabled !== false && e.status === 'checking') ? null : false;
+}
+
export function statusView(e: Pick<EngineInfo, 'status' | 'enabled' | 'ready'> & { kind?: EngineKind; id?: EngineId }): { label: string; tone: Tone } {
if (e.enabled === false || e.status === 'disabled') return { label: 'Off', tone: 'muted' };
if (isUsable(e)) return { label: 'Ready', tone: 'ok' };
diff --git a/frontend/tests/setupNotice.test.mjs b/frontend/tests/setupNotice.test.mjs
new file mode 100644
index 00000000..7aba2d27
--- /dev/null
+++ b/frontend/tests/setupNotice.test.mjs
@@ -0,0 +1,59 @@
+import assert from 'node:assert/strict';
+import test from 'node:test';
+import { loadBundled } from './bundle.mjs';
+
+const m = await loadBundled(`
+ export { SetupNeededCard, parseSetupMeta } from './src/components/SetupNeededCard';
+ export { canRunNow } from './src/engines';
+ export { renderToStaticMarkup } from 'react-dom/server.browser';
+ export { createElement } from 'react';
+`);
+
+const card = (props) =>
+ m.renderToStaticMarkup(
+ m.createElement(m.SetupNeededCard, { botName: 'Architect', spaceName: 'Default', canRun: false, onOpenAccounts: () => {}, ...props }),
+ );
+
+test('only setup_needed meta becomes a setup card', () => {
+ // What src/drivers/engines.rs no_engine_notice saves on the message.
+ assert.deepEqual(m.parseSetupMeta({ kind: 'setup_needed', reason: 'no_account' }), { reason: 'no_account' });
+ assert.deepEqual(m.parseSetupMeta({ kind: 'setup_needed', reason: 'host_off' }), { reason: 'host_off' });
+ assert.deepEqual(m.parseSetupMeta({ kind: 'setup_needed' }), { reason: 'no_account' });
+ // The messages API sends meta as a JSON string.
+ assert.deepEqual(m.parseSetupMeta('{"kind":"setup_needed","reason":"no_account"}'), { reason: 'no_account' });
+ assert.equal(m.parseSetupMeta({ kind: 'ask_user' }), null);
+ assert.equal(m.parseSetupMeta(null), null);
+ assert.equal(m.parseSetupMeta('setup_needed'), null);
+ assert.equal(m.parseSetupMeta('{"kind":"ask_user"}'), null);
+});
+
+test('the card offers Add an account, and says where it is', () => {
+ const html = card({ meta: { reason: 'no_account' } });
+ assert.match(html, /Architect can(’|&#x27;|')t answer yet/);
+ assert.match(html, /No account can run bots in Default yet/);
+ assert.match(html, /<button[^>]*>.*Add an account<\/button>/s);
+ assert.doesNotMatch(html, /Settings → Engines/);
+
+ const off = card({ meta: { reason: 'host_off' } });
+ assert.match(off, /This machine is off in Default/);
+ assert.match(off, /Add an account/);
+});
+
+test('once an account works, the card says to send again and drops the button', () => {
+ const html = card({ meta: { reason: 'no_account' }, canRun: true });
+ assert.match(html, /Architect can answer now/);
+ assert.match(html, /Send your message again/);
+ assert.doesNotMatch(html, /<button/);
+});
+
+test('canRunNow is unknown while loading or checking, never a false "nothing can run"', () => {
+ const e = (id, status, over = {}) => ({ id, status, enabled: true, ...over });
+ assert.equal(m.canRunNow(null), null);
+ assert.equal(m.canRunNow([]), null);
+ assert.equal(m.canRunNow([e('claude', 'checking'), e('codex', 'signed_out')]), null);
+ assert.equal(m.canRunNow([e('claude', 'signed_out'), e('codex', 'not_installed')]), false);
+ assert.equal(m.canRunNow([e('claude', 'checking', { enabled: false }), e('codex', 'signed_out')]), false);
+ assert.equal(m.canRunNow([e('claude', 'signed_out', { ready: true })]), true);
+ assert.equal(m.canRunNow([e('claude', 'ready'), e('codex', 'checking')]), true);
+ assert.equal(m.canRunNow([e('claude', 'ready', { enabled: false })]), false);
+});
diff --git a/src/drivers/api.rs b/src/drivers/api.rs
index a8945913..0783a110 100644
--- a/src/drivers/api.rs
+++ b/src/drivers/api.rs
@@ -46,7 +46,7 @@ async fn api_model_name(
Some(m) => Ok(m.id),
None if engine == super::engines::EngineId::AnthropicApi => Ok(DEFAULT_CLAUDE_MODEL.into()),
None => Err(format!(
- "Couldn't find a model to run on the {}: its model list didn't load. Check the key in Settings → Engines.",
+ "Couldn't find a model to run on the {}: its model list didn't load. Check the key in Space settings → Accounts.",
engine.name()
)),
}
diff --git a/src/drivers/engines.rs b/src/drivers/engines.rs
index c4dba4d0..83356448 100644
--- a/src/drivers/engines.rs
+++ b/src/drivers/engines.rs
@@ -16,7 +16,19 @@ use std::time::Duration;
pub const PROBE_TIMEOUT: Duration = Duration::from_secs(10);
/// What a turn gets when no engine at all can run.
-pub const NO_ENGINE_MESSAGE: &str = "No engine is available — check Settings → Engines.";
+pub const NO_ENGINE_MESSAGE: &str = "No account can run bots here yet. Add one in Space settings → Accounts.";
+
+/// What a turn gets when This machine is off in the space and no other account is on.
+pub const HOST_OFF_MESSAGE: &str =
+ "This machine is off in this space and no other account is on. Turn one on in Space settings → Accounts.";
+
+/// The chat message `bot` leaves when nothing can run its turn, and its `meta`: kind
+/// `setup_needed`, so the app shows a card with a button to Accounts instead of a reply.
+/// `reason` is `host_off` when This machine is switched off in the space, else `no_account`.
+pub fn no_engine_notice(bot: &str, host_off: bool) -> (String, Value) {
+ let (reason, text) = if host_off { ("host_off", HOST_OFF_MESSAGE) } else { ("no_account", NO_ENGINE_MESSAGE) };
+ (format!("⚠️ [{bot}] {text}"), serde_json::json!({ "kind": "setup_needed", "reason": reason }))
+}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize)]
#[serde(rename_all = "snake_case")]
@@ -997,7 +1009,7 @@ fn unavailable(target_model: &str, reports: &[EngineReport]) -> String {
})
.collect();
format!(
- "'{target_model}' can't run right now ({}). Fix it in Settings → Engines, or pick another engine for this bot.",
+ "'{target_model}' can't run right now ({}). Fix it in Space settings → Accounts, or pick another engine for this bot.",
why.join("; ")
)
}
@@ -1006,6 +1018,21 @@ fn unavailable(target_model: &str, reports: &[EngineReport]) -> String {
mod tests {
use super::*;
+ #[test]
+ fn no_engine_notice_flags_the_setup_card() {
+ let (text, meta) = no_engine_notice("Architect", false);
+ assert_eq!(text, format!("⚠️ [Architect] {NO_ENGINE_MESSAGE}"));
+ assert!(text.contains("Space settings → Accounts"));
+ assert!(!text.contains("Settings → Engines"));
+ assert_eq!(meta, serde_json::json!({ "kind": "setup_needed", "reason": "no_account" }));
+
+ let (text, meta) = no_engine_notice("DevOps", true);
+ assert!(text.starts_with("⚠️ [DevOps] This machine is off"));
+ assert!(text.contains("Space settings → Accounts"));
+ assert_eq!(meta["kind"], "setup_needed");
+ assert_eq!(meta["reason"], "host_off");
+ }
+
#[test]
fn versions_parse_from_each_cli() {
assert_eq!(parse_version("2.1.296 (Claude Code)\n").as_deref(), Some("2.1.296"));
diff --git a/src/server/routes.rs b/src/server/routes.rs
index f49c962a..26cc766e 100644
--- a/src/server/routes.rs
+++ b/src/server/routes.rs
@@ -1131,14 +1131,7 @@ async fn run_kwant_turn_inner(
== Some(crate::profiles::Engine::Custom.as_str());
if available_models.is_empty() && !pinned_custom {
// Say why when it's this space's own switch, so nobody hunts for a broken engine
- let text = if host_off.is_empty() {
- format!("⚠️ [{}] {}", target_kwant.name, crate::drivers::engines::NO_ENGINE_MESSAGE)
- } else {
- format!(
- "⚠️ [{}] This machine is off in this space and no other account is on. Turn one on in Settings → Engines.",
- target_kwant.name
- )
- };
+ let (text, meta) = crate::drivers::engines::no_engine_notice(&target_kwant.name, !host_off.is_empty());
event_broadcast.send(RuntimeEvent::TextDelta(text.clone()));
event_broadcast.send(RuntimeEvent::TurnComplete {
tokens: 0,
@@ -1150,7 +1143,7 @@ async fn run_kwant_turn_inner(
reasoning_content: opts.label.clone(),
..scope.message("kwant", &target_kwant.name, text.clone())
};
- scope.save(&msg, None).await;
+ scope.save(&msg, Some(meta)).await;
return Err(text);
}
let route = match router.route_prompt_with_models(&prompt, "chat", &available_models).await {
diff --git a/tests/engine_routing_test.rs b/tests/engine_routing_test.rs
index 0c403bd4..2c197e00 100644
--- a/tests/engine_routing_test.rs
+++ b/tests/engine_routing_test.rs
@@ -184,7 +184,7 @@ async fn turns_skip_engines_that_cannot_run() {
// 4. Nothing can run now: a clear message, and no CLI is started
let text = turn_text(&app, &state, &kid).await;
- assert!(text.contains("No engine is available — check Settings"), "{text}");
+ assert!(text.contains("No account can run bots here yet. Add one in Space settings → Accounts."), "{text}");
assert_eq!(turns_run(tmp.path()), 2);
// 5. Signed in again and re-checked: claude is back. A kwant pinned to codex (not installed)