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.

Panel and Custom API polish: idle placeholder, honest footer, refused-key row, Agent Maestro hint

Lin (kwant bot)4fc0d900f3c3
diff --git a/docs/llm-profiles.md b/docs/llm-profiles.md
index 02c248fa..19a4c107 100644
--- a/docs/llm-profiles.md
+++ b/docs/llm-profiles.md
@@ -40,8 +40,8 @@ several; they belong to that space only. The base URL is cut back to the API roo
`…/chat/completions` or `…/messages` is removed; Anthropic gets `/v1` added), must be http(s), and
may not carry a user, password, query or fragment, so a key never sits in it. The account is
checked with `GET {base}/models` when it is created or changed, on `POST …/check`, and again
-when the account list or the Engines page is read and the last check is over a minute old: `ready`, `unreachable` ("Nothing is answering at <url>. Is Agent Maestro /
-the server running?"), `key_rejected` or `error`, with a readable `detail`. A server that lists
+when the account list or the Engines page is read and the last check is over a minute old: `ready`, `unreachable` ("Nothing is answering at <url>. Is the server running?", naming Agent Maestro
+instead for its address), `key_rejected` or `error`, with a readable `detail`. A server that lists
no models is ready when the account has a `model`. A turn runs the bot's pinned model
(`custom:<model id>`) as is, else the account's `model`, else the first listed model for the
effort's tier; replies stream. MCP tools are offered on `openai-chat` only (`supports_tools`);
diff --git a/frontend/src/components/EngineAccounts.tsx b/frontend/src/components/EngineAccounts.tsx
index 88929b20..c1678177 100644
--- a/frontend/src/components/EngineAccounts.tsx
+++ b/frontend/src/components/EngineAccounts.tsx
@@ -15,7 +15,8 @@ import {
isThirdPartyLabel,
newAccountFor,
profilesApi,
- protocolLabel,
+ customKindText,
+ customModelText,
safeExternalUrl,
} from '../profiles';
@@ -557,7 +558,7 @@ const AccountRow: React.FC<{
const kindText = isSystem
? `The ${engine.name.replace(/ CLI$/, '')} login on this computer`
: isCustom
- ? `${protocolLabel(p.custom?.protocol ?? '')}${p.has_key ? ' · key saved' : ''}`
+ ? customKindText(p)
: p.kind === 'api_key'
? 'API key'
: `${engine.name.replace(/ CLI$/, '')} subscription`;
@@ -643,9 +644,11 @@ const AccountRow: React.FC<{
{p.custom.base_url}
</span>
</p>
- <p className="text-[11px] text-zinc-500">
- Model: <span className="text-zinc-300">{p.custom.model ?? (p.custom.models.length ? 'each bot’s pick, else the server’s first' : 'none set')}</span>
- </p>
+ {customModelText(p.custom) !== null && (
+ <p className="text-[11px] text-zinc-500" data-custom-model>
+ Model: <span className="text-zinc-300">{customModelText(p.custom)}</span>
+ </p>
+ )}
{!p.custom.supports_tools && (
<p data-no-tools className="inline-flex items-center gap-1 px-1.5 py-0.5 rounded-md bg-amber-500/10 border border-amber-500/25 text-[10.5px] text-amber-200">
<Wrench size={10} aria-hidden="true" /> No tools (Anthropic format)
diff --git a/frontend/src/components/VirtualMachinePane.tsx b/frontend/src/components/VirtualMachinePane.tsx
index 209269cb..b675c933 100644
--- a/frontend/src/components/VirtualMachinePane.tsx
+++ b/frontend/src/components/VirtualMachinePane.tsx
@@ -25,7 +25,7 @@ import { playSfx } from '../audio/chiptune';
import { mapBrowserPoint } from '../browserViewport';
import { useBrowserStream } from '../useBrowserStream';
import { ComputerModeChip, ComputerModeError, LocalBrowserNote, OpenWindowButton, useComputerMode } from './ComputerModeSwitch';
-import { showsLocalWindow } from '../computerMode';
+import { browserFooterLabel, isBlankPage, showsLocalWindow } from '../computerMode';
export interface TerminalLogEntry {
command: string;
@@ -102,7 +102,15 @@ export const VirtualMachinePane: React.FC<VirtualMachinePaneProps> = ({
const imageRef = useRef<HTMLImageElement>(null);
const viewportRef = useRef<HTMLDivElement>(null);
- const currentScreenshot = stream.frame?.image || screenshotBase64;
+ // Once the stream reports where the tab is, trust it; before that, the last URL the app heard of.
+ const pageUrl = stream.location ? stream.location.url : activeUrl;
+ const currentScreenshot = isBlankPage(pageUrl) ? null : stream.frame?.image || screenshotBase64;
+ // A hidden frame never loads, so acknowledge it here or the stream stalls waiting for the ack.
+ const blankFrameId = isBlankPage(pageUrl) ? stream.frame?.id : undefined;
+ const { acknowledgeFrame } = stream;
+ useEffect(() => {
+ if (blankFrameId !== undefined) acknowledgeFrame(blankFrameId);
+ }, [blankFrameId, acknowledgeFrame]);
const controlError = stream.error || (!stream.connected ? browserError : null);
// A live stream is ready; otherwise trust isRunning only while no error says the service is down.
const browserReady = stream.connected || (isRunning && !controlError);
@@ -890,22 +898,14 @@ export const VirtualMachinePane: React.FC<VirtualMachinePaneProps> = ({
{/* Footer Status */}
<div className="p-2.5 border-t border-zinc-800 bg-zinc-900/60 flex items-center justify-between text-[11px] text-zinc-400">
- {isWindow ? (
- <div className="flex items-center gap-1.5">
- <Laptop size={12} className="text-amber-300/80" />
- <span>Chrome window on your computer</span>
- </div>
- ) : isLocal ? (
- <div className="flex items-center gap-1.5">
- <Laptop size={12} className={browserReady ? 'text-amber-300/80' : 'text-zinc-500'} />
- <span>{browserReady ? 'Chrome on your computer' : 'Chrome offline'}</span>
- </div>
- ) : (
- <div className="flex items-center gap-1.5">
+ <div className="flex items-center gap-1.5" data-browser-footer>
+ {isLocal ? (
+ <Laptop size={12} className={browserReady || isWindow ? 'text-amber-300/80' : 'text-zinc-500'} />
+ ) : (
<Cpu size={12} className={browserReady ? 'text-emerald-400' : 'text-zinc-500'} />
- <span>{browserReady ? 'Browser Ready' : 'Browser Offline'}</span>
- </div>
- )}
+ )}
+ <span>{browserFooterLabel(computer.state.settings, browserReady)}</span>
+ </div>
{onRestartVm && !isWindow && (
<button
type="button"
diff --git a/frontend/src/computerMode.ts b/frontend/src/computerMode.ts
index 44413b40..7efb8d1f 100644
--- a/frontend/src/computerMode.ts
+++ b/frontend/src/computerMode.ts
@@ -28,6 +28,19 @@ export const LOCAL_BROWSER_NOTE = "Your bots' Chrome is open as a window on your
/** Whether the browser is in its own window instead of the app's live view. */
export const showsLocalWindow = (s: ComputerSettings | null | undefined) => s?.mode === 'local' && s.window.visible;
+/** A tab the bot hasn't opened anything in yet. Its frame is an empty page (black on macOS), so the panel shows "Browser idle". */
+export const isBlankPage = (url: string | null | undefined) => {
+ const u = (url ?? '').trim();
+ return u === '' || u === 'about:blank';
+};
+
+/** The browser panel's footer: where Chrome runs and where you see it. */
+export function browserFooterLabel(s: ComputerSettings | null | undefined, ready: boolean): string {
+ if (s?.mode !== 'local') return ready ? 'Browser Ready' : 'Browser Offline';
+ if (s.window.visible) return 'Chrome window on your computer';
+ return ready ? 'Chrome shown here (no window)' : 'Chrome offline';
+}
+
/** Fired on window after a successful switch so every open control shows the new mode. */
export const COMPUTER_MODE_EVENT = 'kwnt:computer-mode';
diff --git a/frontend/src/profiles.ts b/frontend/src/profiles.ts
index 0c4ff741..a8b04785 100644
--- a/frontend/src/profiles.ts
+++ b/frontend/src/profiles.ts
@@ -172,6 +172,20 @@ export function accountState(p: Profile, now = Date.now()): AccountState {
return { label: 'Unknown', tone: 'muted', detail: p.kind === 'system' ? 'Uses this computer’s login' : 'Couldn’t check the sign-in (is the CLI installed?)' };
}
+/** The format and key note under a Custom API account's name; "key refused" once the server turned the key down. */
+export function customKindText(p: Pick<Profile, 'has_key' | 'custom'>): string {
+ const format = protocolLabel(p.custom?.protocol ?? '');
+ if (!p.has_key) return format;
+ return `${format} · ${p.custom?.status === 'key_rejected' ? 'key refused' : 'key saved'}`;
+}
+
+/** The "Model:" line for a Custom API account, or null when it would say nothing true (the server isn't answering). */
+export function customModelText(c: CustomServer): string | null {
+ if (c.model) return c.model;
+ if (c.status !== 'ready') return null;
+ return c.models.length ? 'each bot’s pick, else the server’s first' : 'none set';
+}
+
/** A Custom API account's check, with the server's own words when it failed. */
function customState(c: CustomServer | null): AccountState {
switch (c?.status) {
diff --git a/frontend/tests/browserPanel.test.mjs b/frontend/tests/browserPanel.test.mjs
new file mode 100644
index 00000000..dcf803aa
--- /dev/null
+++ b/frontend/tests/browserPanel.test.mjs
@@ -0,0 +1,52 @@
+import assert from 'node:assert/strict';
+import test from 'node:test';
+import { loadBundled } from './bundle.mjs';
+
+// The sound effects module reads its mute flag on load.
+globalThis.localStorage ??= { getItem: () => null, setItem: () => {} };
+
+const m = await loadBundled(`
+ export { isBlankPage, browserFooterLabel } from './src/computerMode';
+ export { VirtualMachinePane } from './src/components/VirtualMachinePane';
+ export { renderToStaticMarkup } from 'react-dom/server.browser';
+ export { createElement } from 'react';
+`);
+
+const settings = (mode, visible = false) => ({
+ mode,
+ available: { local: true, vm: true },
+ reasons: { local: null, vm: null },
+ window: { visible, available: true, reason: null },
+});
+const pane = (props) =>
+ m.renderToStaticMarkup(m.createElement(m.VirtualMachinePane, { isOpen: true, onClose: () => {}, teamId: 'k1', screenshotBase64: 'AAAA', ...props }));
+
+test('an empty or about:blank tab counts as not opened yet', () => {
+ for (const url of ['', ' ', 'about:blank', null, undefined]) assert.equal(m.isBlankPage(url), true, String(url));
+ for (const url of ['https://maps.google.com/', 'about:blank#x', 'http://127.0.0.1:8080/']) assert.equal(m.isBlankPage(url), false, url);
+});
+
+test('before the bot opens a page the panel says "Browser idle" instead of the blank frame', () => {
+ for (const activeUrl of ['', 'about:blank']) {
+ const html = pane({ activeUrl });
+ assert.match(html, /Browser idle/);
+ assert.doesNotMatch(html, /alt="Browser Viewport"/);
+ }
+});
+
+test('once the bot has opened a page the live frame shows', () => {
+ const html = pane({ activeUrl: 'https://www.google.com/maps' });
+ assert.match(html, /alt="Browser Viewport"/);
+ assert.match(html, /data:image\/jpeg;base64,AAAA/);
+ assert.doesNotMatch(html, /Browser idle/);
+});
+
+test('the footer says where Chrome runs and where you see it', () => {
+ assert.equal(m.browserFooterLabel(settings('local'), true), 'Chrome shown here (no window)');
+ assert.equal(m.browserFooterLabel(settings('local', true), true), 'Chrome window on your computer');
+ assert.equal(m.browserFooterLabel(settings('local'), false), 'Chrome offline');
+ assert.equal(m.browserFooterLabel(settings('vm'), true), 'Browser Ready');
+ assert.equal(m.browserFooterLabel(settings('vm'), false), 'Browser Offline');
+ // Settings not loaded yet: no claim about the user's computer.
+ assert.equal(m.browserFooterLabel(null, true), 'Browser Ready');
+});
diff --git a/frontend/tests/customApi.test.mjs b/frontend/tests/customApi.test.mjs
index bbb22307..aef1056c 100644
--- a/frontend/tests/customApi.test.mjs
+++ b/frontend/tests/customApi.test.mjs
@@ -6,7 +6,7 @@ globalThis.localStorage ??= { getItem: () => null, setItem: () => {} };
const m = await loadBundled(`
export * from './src/engines';
- export { accountState, engineOfModel, readyCustomAccounts, accountUsable, CUSTOM_PRESETS } from './src/profiles';
+ export { accountState, engineOfModel, readyCustomAccounts, accountUsable, CUSTOM_PRESETS, customKindText, customModelText } from './src/profiles';
export { EnginesPanel } from './src/components/EnginesPanel';
export { CustomServerForm } from './src/components/EngineAccounts';
export { ModelPicker } from './src/components/ModelPicker';
@@ -84,6 +84,26 @@ test('the Custom API card lists several servers with status, checks and the no-t
assert.match(html, /data-custom-url="true"[^>]*>http:\/\/localhost:23333\/api\/anthropic\/v1</);
});
+test('a refused key reads as refused, without a model line it can\'t vouch for', () => {
+ assert.equal(m.customKindText(badKey), 'OpenAI-compatible · key refused');
+ assert.equal(m.customKindText({ ...copilot, has_key: true }), 'OpenAI-compatible · key saved');
+ assert.equal(m.customKindText(copilot), 'OpenAI-compatible');
+ // The server answered 401, so whatever list it has isn't known to work.
+ assert.equal(m.customModelText({ ...badKey.custom, models: copilot.custom.models }), null);
+ assert.equal(m.customModelText(down.custom), null);
+ assert.equal(m.customModelText(copilot.custom), 'each bot’s pick, else the server’s first');
+ assert.equal(m.customModelText(server({ models: [] })), 'none set');
+ // A model the person chose is shown whatever the status.
+ assert.equal(m.customModelText({ ...badKey.custom, model: 'gpt-4.1' }), 'gpt-4.1');
+
+ const html = panel([customEngine()], [{ ...badKey, custom: { ...badKey.custom, models: copilot.custom.models } }]);
+ assert.match(html, /key refused/);
+ assert.doesNotMatch(html, /key saved/);
+ assert.doesNotMatch(html, /data-custom-model/);
+ assert.doesNotMatch(html, /none set/);
+ assert.match(panel([customEngine({ ready: true })], [copilot]), /data-custom-model/);
+});
+
test('without servers the card invites one, naming Agent Maestro', () => {
const html = panel([customEngine()], []);
assert.match(html, /No servers yet\./);
diff --git a/src/drivers/custom.rs b/src/drivers/custom.rs
index 87b9c0f5..aaa26799 100644
--- a/src/drivers/custom.rs
+++ b/src/drivers/custom.rs
@@ -113,9 +113,20 @@ pub fn models_url(base: &str) -> String {
format!("{base}/models")
}
-/// The message for a server that doesn't answer at all.
+/// The message for a server that doesn't answer at all. It names Agent Maestro only for its
+/// address (localhost:23333 or its `/api/openai` / `/api/anthropic` paths).
pub fn not_answering(base: &str) -> String {
- format!("Nothing is answering at {base}. Is Agent Maestro / the server running?")
+ let server = if is_agent_maestro(base) { "Agent Maestro" } else { "the server" };
+ format!("Nothing is answering at {base}. Is {server} running?")
+}
+
+fn is_agent_maestro(base: &str) -> bool {
+ let lower = base.to_ascii_lowercase();
+ let rest = lower.split_once("://").map_or(lower.as_str(), |(_, r)| r);
+ let (authority, path) = rest.split_once('/').unwrap_or((rest, ""));
+ let local = ["localhost:23333", "127.0.0.1:23333", "[::1]:23333"].contains(&authority);
+ let path = format!("/{path}");
+ local || path.starts_with("/api/openai") || path.starts_with("/api/anthropic")
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
@@ -320,6 +331,21 @@ mod tests {
}
}
+ #[test]
+ fn only_agent_maestro_addresses_name_agent_maestro() {
+ for base in [
+ "http://localhost:23333/api/openai/v1",
+ "http://127.0.0.1:23333/api/anthropic/v1",
+ "http://localhost:23333/v1",
+ "http://192.168.1.5:9000/api/openai/v1",
+ ] {
+ assert_eq!(not_answering(base), format!("Nothing is answering at {base}. Is Agent Maestro running?"));
+ }
+ for base in ["http://localhost:1234/v1", "https://openrouter.ai/api/v1", "http://localhost:233330/v1"] {
+ assert_eq!(not_answering(base), format!("Nothing is answering at {base}. Is the server running?"));
+ }
+ }
+
#[test]
fn model_ids_are_checked() {
assert_eq!(clean_model(" ").unwrap(), None);
diff --git a/tests/custom_api_test.rs b/tests/custom_api_test.rs
index d75d36fc..ddca9173 100644
--- a/tests/custom_api_test.rs
+++ b/tests/custom_api_test.rs
@@ -450,7 +450,7 @@ async fn a_server_that_is_not_running_says_so() {
)
.await;
assert_eq!(s, StatusCode::CREATED, "{acct}");
- let expected = format!("Nothing is answering at http://127.0.0.1:{port}/v1. Is Agent Maestro / the server running?");
+ let expected = format!("Nothing is answering at http://127.0.0.1:{port}/v1. Is the server running?");
assert_eq!(acct["custom"]["status"], "unreachable", "{acct}");
assert_eq!(acct["custom"]["detail"], expected.as_str());
assert_eq!(acct["has_key"], false);