Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
feat(engines): an OpenAI-compatible server shows its provider's mark (#4067)
Milind Soni9338b7410fc0
diff --git a/docs/custom-engines.md b/docs/custom-engines.mdindex 1a758a5292..23c783ee60 100644--- a/docs/custom-engines.md+++ b/docs/custom-engines.md@@ -6,17 +6,19 @@ after editing (instance entries are read at boot).## Provider icons-In **Settings → Engines**, expand an instance and choose its **Provider icon**.-The built-in choices include OpenAI, Anthropic, Google Gemini, Microsoft Azure,-Amazon Bedrock (AWS), xAI, DeepSeek, Meta, Mistral AI, Qwen, Moonshot AI,-Cohere, and OpenRouter. You can also upload a PNG, JPEG, or WebP image up to-128 KB and 1024 × 1024 pixels. **Reset** restores the default icon.+Each instance shows its driver's mark. An OpenAI-compatible server shows the+mark of whoever runs it, read from the host in its address: `api.deepseek.com`+shows DeepSeek, `<resource>.openai.azure.com` Microsoft Azure,+`dashscope-intl.aliyuncs.com` Qwen, `openrouter.ai` OpenRouter, and so on+(the list is `SERVER_HOSTS` in `server/provider-icon.ts`). A server without a+mark of its own, such as Groq, Together, Ollama or LM Studio, keeps the default.-Each instance has its own icon, independent of its driver or API protocol.-Changes made in Settings apply immediately without restarting the engine.-For file-based configuration, add `"icon": { "kind": "preset", "preset": "azure" }`-alongside `driver` and `displayName`. Custom uploads are stored as embedded image-data; the app does not fetch remote icon URLs.+An icon stored on the instance still wins: add+`"icon": { "kind": "preset", "preset": "azure" }` alongside `driver` and+`displayName`. The presets are OpenAI, Anthropic, Google Gemini, Microsoft+Azure, Amazon Bedrock (AWS), xAI, DeepSeek, Meta, Mistral AI, Qwen, Moonshot+AI, Cohere and OpenRouter. Custom images saved before v0.1.102 keep rendering;+the app never fetches remote icon URLs.## Any ACP agent (a CLI you spawn)diff --git a/server/index.ts b/server/index.tsindex e307900092..193d164211 100644--- a/server/index.ts+++ b/server/index.ts@@ -287,7 +287,7 @@ import { CloudCreditProvider } from "./cloud-credit-provider.ts";import { createCreditMoves } from "./cloud-credit-moves.ts"; import { createRoutineHoldsHost } from "./host/routine-holds-host.ts";import { TRIAL_CREDIT_OWN_AI, TRIAL_KEY_HELD } from "./trial-credit.ts"; import { createHeldKeys } from "./cloud-held-keys.ts";import type { ProviderInstance } from "./contracts.ts";-import { readyToRun, selectDefaultModelSelection, withInstanceConfig, withNewBotEffort, type SelectableInstance } from "./default-model-selection.ts"; import { configIdentity, createTestedAi } from "./tested-ai.ts";+import { readyToRun, selectDefaultModelSelection, withInstanceConfig, withNewBotEffort, type SelectableInstance } from "./default-model-selection.ts"; import { configIdentity, createTestedAi } from "./tested-ai.ts"; import { instanceIcon } from "./provider-icon.ts";import { threadModelFallback, type ThreadEngine } from "./thread-model.ts";import { computerEngineMoveText, removedComputerInstanceIds, writeComputerEngineMoveLines } from "./computer-engine-removal.ts";import { cancelPeerApprovalsFor, cancelPeerApprovalsForThread, dismissStalePeerCards, peerApprovalFailure, requestPeerApproval, resolvePeerComms, type ApprovalBus } from "./peer-approval.ts";@@ -12003,7 +12003,7 @@ async function describeInstances() {const entry = configs[instance.instanceId];const described = {...instance, ...testedAi.info(instance),- ...(entry?.icon ? { icon: entry.icon } : {}),+ ...instanceIcon(entry),...(entry?.access ? { access: entry.access } : {}), ...(entry?.driver === "openai-compat" && typeof (entry.config as { replyWaitMinutes?: unknown } | undefined)?.replyWaitMinutes === "number" ? { replyWaitMinutes: (entry.config as { replyWaitMinutes: number }).replyWaitMinutes } : {}), ...(heldKeys?.refusal(instance.instanceId) ? { snapshot: { state: "unavailable" as const, reason: TRIAL_KEY_HELD } } : {}),};if (hostedModels) return { ...described, readOnly: true,diff --git a/server/instance-icons.e2e.test.ts b/server/instance-icons.e2e.test.tsnew file mode 100644index 0000000000..6da18dcc1c--- /dev/null+++ b/server/instance-icons.e2e.test.ts@@ -0,0 +1,56 @@+// Real server: the engine list carries each OpenAI-compatible server's mark, so every client shows it without the address.+import { spawn, type ChildProcess } from "node:child_process";+import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs";+import { tmpdir } from "node:os";+import { join } from "node:path";+import { fileURLToPath } from "node:url";+import { afterEach, expect, it } from "vitest";+import { verificationServerEnvironment } from "../scripts/control-omb.ts";+import { removeTempDir, waitForExit } from "./testing/cleanup.ts";+import { freePortBlock } from "./testing/ports.ts";++const ROOT = fileURLToPath(new URL("..", import.meta.url));+const homes: string[] = [];+const children: ChildProcess[] = [];++afterEach(async () => {+ for (const child of children.splice(0)) await waitForExit(child, { signal: "SIGTERM" });+ for (const home of homes.splice(0)) await removeTempDir(home);+});++// No key and a fixed model list: the server never asks these hosts for anything.+const server = (url: string, extra: object = {}) => ({ driver: "openai-compat", ...extra, config: { url, managedModels: ["fixture-model"] } });++it("lists an OpenAI-compatible server with its provider's mark, and a stored icon over it", async () => {+ const home = mkdtempSync(join(tmpdir(), "omb-instance-icons-"));+ homes.push(home);+ mkdirSync(join(home, "tmp"), { recursive: true });+ writeFileSync(join(home, "config.json"), JSON.stringify({+ instances: {+ deepseekServer: server("https://api.deepseek.com/v1", { displayName: "DeepSeek" }),+ lookalike: server("https://api.openai.com.evil.test/v1"),+ ownIcon: server("https://api.x.ai/v1", { icon: { kind: "preset", preset: "cohere" } }),+ },+ }));+ const port = await freePortBlock([0, 1]);+ const base = `http://127.0.0.1:${port}`;+ const child = spawn(process.execPath, ["--experimental-strip-types", join(ROOT, "server/index.ts")], {+ cwd: ROOT, env: verificationServerEnvironment(process.env, home, port), stdio: ["ignore", "pipe", "pipe"],+ });+ children.push(child);+ let output = "";+ child.stdout!.on("data", (chunk) => { output += chunk; });+ child.stderr!.on("data", (chunk) => { output += chunk; });+ await expect.poll(async () => {+ if (child.exitCode !== null) throw new Error(`server exited during boot:\n${output}`);+ try { return (await fetch(`${base}/api/health`)).ok; } catch { return false; }+ }, { timeout: 20_000, interval: 50 }).toBe(true);++ const response = await fetch(`${base}/api/instances`, { headers: { origin: base } });+ expect(response.status).toBe(200);+ const { instances } = await response.json() as { instances: Array<{ instanceId: string; icon?: unknown }> };+ const icon = (id: string) => instances.find((instance) => instance.instanceId === id)!.icon;+ expect(icon("deepseekServer")).toEqual({ kind: "preset", preset: "deepseek" });+ expect(icon("lookalike")).toBeUndefined();+ expect(icon("ownIcon")).toEqual({ kind: "preset", preset: "cohere" });+}, 60_000);diff --git a/server/provider-icon.test.ts b/server/provider-icon.test.tsnew file mode 100644index 0000000000..a537dba4e1--- /dev/null+++ b/server/provider-icon.test.ts@@ -0,0 +1,101 @@+import { describe, expect, it } from "vitest";+import { instanceIcon, serverIconPreset } from "./provider-icon.ts";++describe("a server's mark comes from its host", () => {+ it.each([+ ["https://api.openai.com/v1", "openai"],+ ["https://eu.api.openai.com/v1", "openai"],+ ["https://my-team.openai.azure.com/openai/deployments/gpt-5", "azure"],+ ["https://my-team.services.ai.azure.com/models", "azure"],+ ["https://my-team.cognitiveservices.azure.com/openai/v1", "azure"],+ ["https://bedrock-runtime.us-east-1.amazonaws.com/openai/v1", "aws"],+ ["https://generativelanguage.googleapis.com/v1beta/openai", "google"],+ ["https://us-central1-aiplatform.googleapis.com/v1/projects/p/locations/us-central1/endpoints/openapi", "google"],+ ["https://api.x.ai/v1", "xai"],+ ["https://api.deepseek.com", "deepseek"],+ ["https://dashscope.aliyuncs.com/compatible-mode/v1", "qwen"],+ ["https://dashscope-intl.aliyuncs.com/compatible-mode/v1", "qwen"],+ ["https://api.moonshot.ai/v1", "moonshot"],+ ["https://api.moonshot.cn/v1", "moonshot"],+ ["https://api.mistral.ai/v1", "mistral"],+ ["https://api.cohere.com/compatibility/v1", "cohere"],+ ["https://api.cohere.ai/compatibility/v1", "cohere"],+ ["https://openrouter.ai/api/v1", "openrouter"],+ ["https://api.anthropic.com/v1", "anthropic"],+ ["https://api.llama.com/compat/v1", "meta"],+ ])("%s shows %s", (url, preset) => {+ expect(serverIconPreset(url)).toBe(preset);+ });++ it("ignores the port, the scheme between http and https, letter case and a trailing dot", () => {+ expect(serverIconPreset("https://api.openai.com:443/v1")).toBe("openai");+ expect(serverIconPreset("https://api.openai.com:8443/v1")).toBe("openai");+ expect(serverIconPreset("http://api.deepseek.com/v1")).toBe("deepseek");+ expect(serverIconPreset("HTTPS://API.DeepSeek.COM/v1")).toBe("deepseek");+ expect(serverIconPreset("https://api.openai.com./v1")).toBe("openai");+ });++ it.each([+ "https://api.openai.com.evil.test/v1",+ "https://evil.test/api.openai.com/v1",+ "https://[email protected]/v1",+ "https://evil.test/v1?host=api.openai.com",+ "https://evil.test/#api.openai.com",+ "https://notopenrouter.ai/api/v1",+ "https://openrouter.ai.evil.test/api/v1",+ "https://my-team.openai.azure.com.evil.test/openai",+ "https://bedrock-runtime.us-east-1.amazonaws.com.evil.test/openai/v1",+ "https://bedrock-runtime.my-bucket.s3.amazonaws.com/openai/v1",+ "https://dashscope.aliyuncs.com.evil.test/compatible-mode/v1",+ "https://evil-dashscope.aliyuncs.com/compatible-mode/v1",+ "https://api.x.ai.evil.test/v1",+ ])("never matches the look-alike %s", (url) => {+ expect(serverIconPreset(url)).toBeUndefined();+ });++ it.each([+ "http://127.0.0.1:11434/v1",+ "http://localhost:11434/v1",+ "http://localhost:1234/v1",+ "http://[::1]:8080/v1",+ "http://192.168.1.20:11434/v1",+ "https://api.groq.com/openai/v1",+ "https://api.together.xyz/v1",+ "https://api.fireworks.ai/inference/v1",+ ])("keeps the driver's mark for %s, which has no mark of its own", (url) => {+ expect(serverIconPreset(url)).toBeUndefined();+ });++ it("needs an http or https address", () => {+ expect(serverIconPreset("ftp://api.openai.com/v1")).toBeUndefined();+ expect(serverIconPreset("api.openai.com/v1")).toBeUndefined();+ expect(serverIconPreset("")).toBeUndefined();+ });+});++describe("an instance's mark", () => {+ const server = (url: unknown, extra: object = {}) => ({ driver: "openai-compat", config: { url, key: "sk-fixture" }, ...extra });++ it("is the mark of whoever runs an OpenAI-compatible server", () => {+ expect(instanceIcon(server("https://api.deepseek.com/v1"))).toEqual({ icon: { kind: "preset", preset: "deepseek" } });+ expect(instanceIcon(server("https://dashscope-intl.aliyuncs.com/compatible-mode/v1"))).toEqual({ icon: { kind: "preset", preset: "qwen" } });+ });++ it("keeps a stored icon, preset or custom, over the server's", () => {+ const preset = { kind: "preset", preset: "cohere" } as const;+ const custom = { kind: "custom", dataUrl: "data:image/png;base64,iVBORw0KGgo=" } as const;+ expect(instanceIcon(server("https://api.deepseek.com/v1", { icon: preset }))).toEqual({ icon: preset });+ expect(instanceIcon(server("https://api.deepseek.com/v1", { icon: custom }))).toEqual({ icon: custom });+ expect(instanceIcon({ driver: "claudeAgent", icon: preset })).toEqual({ icon: preset });+ });++ it("leaves the driver's own mark for an unknown or missing address and for other drivers", () => {+ expect(instanceIcon(server("https://llm.example.test/v1"))).toEqual({});+ expect(instanceIcon(server("http://127.0.0.1:11434/v1"))).toEqual({});+ expect(instanceIcon(server(42))).toEqual({});+ expect(instanceIcon({ driver: "openai-compat" })).toEqual({});+ expect(instanceIcon({ driver: "openai-compat", config: null })).toEqual({});+ expect(instanceIcon({ driver: "groq", config: { url: "https://api.openai.com/v1" } })).toEqual({});+ expect(instanceIcon(undefined)).toEqual({});+ });+});diff --git a/server/provider-icon.ts b/server/provider-icon.tsindex 9f9b75bcbb..eb933db3c8 100644--- a/server/provider-icon.ts+++ b/server/provider-icon.ts@@ -1,6 +1,7 @@import { z } from "zod";import { persistableInstanceConfigs, type AppConfig } from "./config.ts";-import { PROVIDER_ICON_PRESETS, type ProviderIcon } from "../shared/provider-icon.ts";+import type { InstanceConfig } from "./contracts.ts";+import { PROVIDER_ICON_PRESETS, type ProviderIcon, type ProviderIconPreset } from "../shared/provider-icon.ts";const iconSchema = z.discriminatedUnion("kind", [z.object({ kind: z.literal("preset"), preset: z.enum(PROVIDER_ICON_PRESETS) }).strict(),@@ -18,3 +19,46 @@ export function withInstanceIcon(cfg: AppConfig, instanceId: string, icon: Provinext.instances = instances;return { ok: true as const, config: next, instances };}++/** Who runs a server, by its host. `*` is one DNS label, or the rest of one. Only providers we have a mark for:+ * Groq, Together, Fireworks, Ollama and LM Studio servers keep the driver's own mark. */+const SERVER_HOSTS: Record<string, ProviderIconPreset> = {+ "api.openai.com": "openai", "*.api.openai.com": "openai",+ "*.openai.azure.com": "azure", "*.services.ai.azure.com": "azure", "*.cognitiveservices.azure.com": "azure",+ "bedrock-runtime.*.amazonaws.com": "aws",+ "generativelanguage.googleapis.com": "google", "aiplatform.googleapis.com": "google", "*-aiplatform.googleapis.com": "google",+ "api.x.ai": "xai",+ "api.deepseek.com": "deepseek",+ "dashscope.aliyuncs.com": "qwen", "dashscope-*.aliyuncs.com": "qwen",+ "api.moonshot.ai": "moonshot", "api.moonshot.cn": "moonshot",+ "api.mistral.ai": "mistral", "codestral.mistral.ai": "mistral",+ "api.cohere.com": "cohere", "api.cohere.ai": "cohere",+ "openrouter.ai": "openrouter", "*.openrouter.ai": "openrouter",+ "api.anthropic.com": "anthropic",+ "api.llama.com": "meta", "api.meta.ai": "meta",+};+const SERVER_MARKS = Object.entries(SERVER_HOSTS).map(([host, preset]) =>+ [new RegExp(`^${host.replaceAll(".", "\\.").replaceAll("*", "[a-z0-9-]+")}$`), preset] as const);++/** The provider whose mark a server address shows. Only the host counts, so a look-alike host+ * (api.openai.com.evil.test) or a provider named in the path or user name never matches. */+export function serverIconPreset(url: string): ProviderIconPreset | undefined {+ let host: string;+ try {+ const parsed = new URL(url);+ if (parsed.protocol !== "https:" && parsed.protocol !== "http:") return undefined;+ host = parsed.hostname.replace(/\.$/, "");+ } catch {+ return undefined;+ }+ return SERVER_MARKS.find(([pattern]) => pattern.test(host))?.[1];+}++/** The mark an instance shows everywhere the instance list goes: a stored icon (set before v0.1.102) wins; an+ * OpenAI-compatible server otherwise shows the mark of whoever runs it; anything else keeps its driver's mark. */+export function instanceIcon(entry: InstanceConfig | undefined): { icon?: ProviderIcon } {+ if (entry?.icon) return { icon: entry.icon };+ const url = entry?.driver === "openai-compat" ? (entry.config as { url?: unknown } | undefined)?.url : undefined;+ const preset = typeof url === "string" ? serverIconPreset(url) : undefined;+ return preset ? { icon: { kind: "preset", preset } } : {};+}