Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
feat(local-inject): discover Rapid-MLX on this Mac
Raullen04520d6227a4
diff --git a/server/drivers/local-inject-matrix.test.ts b/server/drivers/local-inject-matrix.test.tsindex e30ba70aaa..149a92257a 100644--- a/server/drivers/local-inject-matrix.test.ts+++ b/server/drivers/local-inject-matrix.test.ts@@ -198,7 +198,7 @@ describe("Codex provider dialect", () => {expect(codexLocalProviderArgs({}, "lmstudio::qwen2.5-coder:32b")).toEqual([]);});- it.each(["omlx", "exo", "unsloth"] as const)("emits a -c provider for %s without putting the secret on argv", (hostId) => {+ it.each(["omlx", "exo", "unsloth", "rapid_mlx"] as const)("emits a -c provider for %s without putting the secret on argv", (hostId) => {const env: Record<string, string | undefined> = { UNSLOTH_STUDIO_AUTH_TOKEN: "unsloth-secret" };const args = codexLocalProviderArgs(env, encodeInjectId(hostId, "gemma-4-31b-it-bf16"));const rendered = JSON.stringify(args);diff --git a/server/drivers/local-inject.test.ts b/server/drivers/local-inject.test.tsindex 1a5eefbf5f..09cc8375e7 100644--- a/server/drivers/local-inject.test.ts+++ b/server/drivers/local-inject.test.ts@@ -23,6 +23,7 @@ import {loadedIdsFromPayloads,LOCAL_HOSTS,mergeLocalInject,+ probeLocalInjects,resolveInjectId,} from "./local-inject.ts";@@ -44,6 +45,56 @@ describe("inject ids", () => {expect(decodeInjectId("claude-sonnet-5")).toBeNull();expect(decodeInjectId("gpt-5.6-sol")).toBeNull();});++ it("decodes a Rapid-MLX model id", () => {+ expect(decodeInjectId("rapid_mlx::mlx-community/Qwen3.5-4B-MLX-4bit")).toEqual({+ host: "rapid_mlx",+ model: "mlx-community/Qwen3.5-4B-MLX-4bit",+ });+ });+});++describe("Rapid-MLX discovery", () => {+ it.each([undefined, "rapid-secret"])("lists only Rapid-MLX records with API key %s", async (apiKey) => {+ const catalog = await mergeLocalInject(+ { default: "keep", options: [{ id: "keep", label: "Keep" }] },+ { VITEST: "true", OPENMAUSBOT_PROBE_LOCAL_INJECT: "1", RAPID_MLX_API_KEY: apiKey },+ async (url, init) => {+ if (String(url) !== "http://127.0.0.1:8000/v1/models") return new Response("nope", { status: 500 });+ expect(new Headers(init?.headers).get("Authorization")).toBe(`Bearer ${apiKey ?? "rapid-mlx"}`);+ return new Response(JSON.stringify({+ default_model: "other-chat",+ data: [+ { id: "mlx-community/Qwen3.5-4B-MLX-4bit", owned_by: "rapid-mlx", capabilities: ["text", "vision", "tools"] },+ { id: "other-chat", owned_by: "vllm", loaded: true },+ { id: "unknown-chat", loaded: true },+ { id: "nomic-embed", owned_by: "rapid-mlx" },+ { id: "mlx-community/Qwen3-Reranker-0.6B-4bit", owned_by: "rapid-mlx", capabilities: ["rerank"] },+ { id: "mlx-community/embeddinggemma-2-4bit", owned_by: "rapid-mlx", capabilities: ["embedding"] },+ ],+ }));+ },+ );+ expect(catalog.options).toEqual([+ { id: "keep", label: "Keep" },+ {+ id: "rapid_mlx::mlx-community/Qwen3.5-4B-MLX-4bit",+ label: "mlx-community/Qwen3.5-4B-MLX-4bit (Rapid-MLX)",+ custom: true,+ },+ ]);+ });++ it.each(["vllm", undefined])("ignores a server on port 8000 with owned_by %s", async (ownedBy) => {+ const models = await probeLocalInjects({}, async (url) => {+ if (String(url) !== "http://127.0.0.1:8000/v1/models") return new Response("nope", { status: 500 });+ return new Response(JSON.stringify({+ default_model: "other-chat",+ data: [{ id: "other-chat", owned_by: ownedBy, loaded: true }],+ }));+ });+ expect(models).toEqual([]);+ });});describe("contextWindowsFromPs", () => {diff --git a/server/drivers/local-inject.ts b/server/drivers/local-inject.tsindex d73ca42822..b4658da036 100644--- a/server/drivers/local-inject.ts+++ b/server/drivers/local-inject.ts@@ -1,4 +1,4 @@-// Shared local-host inject: probe oMLX / Ollama / EXO / LM Studio / Unsloth, list what they serve+// Shared local-host inject: probe oMLX / Ollama / EXO / LM Studio / Unsloth / Rapid-MLX, list what they serve// under Custom, and decode a pick into a host + API id.import { readFileSync } from "node:fs";import { homedir } from "node:os";@@ -23,6 +23,7 @@ export const LOCAL_HOSTS: LocalHost[] = [{ id: "lmstudio", label: "LM Studio", baseUrl: "http://127.0.0.1:1234/v1", apiKey: "lm-studio" },{ id: "unsloth", label: "Unsloth", baseUrl: "http://127.0.0.1:8888/v1", apiKeyEnv: "UNSLOTH_STUDIO_AUTH_TOKEN" },{ id: "unsloth_api", label: "Unsloth", baseUrl: "http://127.0.0.1:8888/v1", apiKeyEnv: "UNSLOTH_STUDIO_AUTH_TOKEN" },+ { id: "rapid_mlx", label: "Rapid-MLX", baseUrl: "http://127.0.0.1:8000/v1", apiKey: "rapid-mlx", apiKeyEnv: "RAPID_MLX_API_KEY" },];export const INJECT_SEP = "::";@@ -203,7 +204,7 @@ function readUnslothKey(env: Record<string, string | undefined>): string | null}}-function idsFromModelsPayload(payload: unknown): string[] {+function idsFromModelsPayload(payload: unknown, ownedBy?: string): string[] {const records = Array.isArray(payload)? payload: payload && typeof payload === "object" && Array.isArray((payload as { data?: unknown }).data)@@ -212,6 +213,13 @@ function idsFromModelsPayload(payload: unknown): string[] {? (payload as { models: unknown[] }).models: [];return records.flatMap((record) => {+ if (ownedBy) {+ if (!record || typeof record !== "object") return [];+ const row = record as { owned_by?: unknown; capabilities?: unknown };+ if (row.owned_by !== ownedBy) return [];+ // Rapid-MLX also serves embedding and rerank models; only chat models are picks.+ if (Array.isArray(row.capabilities) && !row.capabilities.includes("text")) return [];+ }if (typeof record === "string") return MODEL_ID.test(record) ? [record] : [];if (!record || typeof record !== "object") return [];const id = (record as { id?: unknown; name?: unknown }).id ?? (record as { name?: unknown }).name;@@ -382,6 +390,9 @@ export async function probeLocalInjects(]);const native = host.id === "lmstudio" ? lmStudioV1Catalog(nativePayload) : null;if (native) return { host, ids: native.ids, loaded: native.loaded, windows: native.windows };+ if (host.id === "rapid_mlx") {+ return { host, ids: idsFromModelsPayload(catalog, "rapid-mlx"), loaded: new Set<string>(), windows: new Map<string, number>() };+ }const catalogIds = catalog ? idsFromModelsPayload(catalog) : [];const extraIds = extra ? idsFromModelsPayload(extra) : [];const loaded = loadedIdsFromPayloads(host, catalog ?? extra, extra);