Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

train: members read the engine list without accounts, paths or addresses

milind-sonid48ce8033839
diff --git a/server/routes/instances.test.ts b/server/routes/instances.test.ts
index 45329e8d39..696a562c8a 100644
--- a/server/routes/instances.test.ts
+++ b/server/routes/instances.test.ts
@@ -172,6 +172,18 @@ describe("the engine list", () => {
expect(fake.probes).toHaveLength(2);
expect(await probesAfterList()).toBe(2);
});
+
+ it("shows a member names, models and capabilities only, and never reads the engines afresh for one", async () => {
+ const member = { kind: "session", via: "cookie", scopes: ["client"], session: {} } as unknown as RequestAuth;
+ const describeInstances = async () => [{ instanceId: "a", driverKind: "fake", displayName: "Fake", models: { default: "m", options: [{ id: "m", label: "M" }] },
+ capabilities: { queueing: true }, cli: "/home/owner/bin/fake", cliCandidates: ["/home/owner/bin/fake"], url: "https://llm.internal.example",
+ claudeAccount: { configDir: "/home/owner/.claude" }, snapshot: { state: "available", authenticated: true, account: { email: "[email protected]" } } }];
+ const { call, fake } = await serve({ describeInstances } as Partial<InstanceRouteDeps>, member);
+ const { instances } = await call("GET", "/api/instances?fresh=1");
+ expect(instances).toEqual([{ instanceId: "a", driverKind: "fake", displayName: "Fake", readOnly: true, models: { default: "m", options: [{ id: "m", label: "M" }] },
+ capabilities: { queueing: true }, snapshot: { state: "available", authenticated: true } }]);
+ expect(fake.probes).toHaveLength(0);
+ });
});
describe("whether the server can start a bot", () => {
diff --git a/server/routes/instances.ts b/server/routes/instances.ts
index d787d066bd..ecf8691892 100644
--- a/server/routes/instances.ts
+++ b/server/routes/instances.ts
@@ -71,6 +71,17 @@ export interface InstanceRouteDeps {
endpointModelsReadable?(config: { url: string; key: string; catalog?: unknown }): Promise<boolean>;
}
+/** The engines as a member (a client-scope session) sees them: names, models and capabilities, never the signed-in
+ * account, CLI paths, sign-in commands or a server's address. */
+function memberInstances(described: unknown): unknown[] {
+ return (Array.isArray(described) ? described as Array<Record<string, any>> : []).map((instance) => ({
+ instanceId: instance.instanceId, driverKind: instance.driverKind, displayName: instance.displayName, readOnly: true,
+ ...(instance.icon ? { icon: instance.icon } : {}), ...(instance.access ? { access: instance.access } : {}),
+ models: instance.models, ...(instance.capabilities ? { capabilities: instance.capabilities } : {}),
+ snapshot: { state: instance.snapshot?.state, ...(typeof instance.snapshot?.authenticated === "boolean" ? { authenticated: instance.snapshot.authenticated } : {}) },
+ }));
+}
+
export function createInstanceRoutes(deps: InstanceRouteDeps): RouteHandler {
const {
store, cfg, registry, sessions, providerAuthSessions, hostedModels, providerConfigBusy, providerInstancesChanging,
@@ -118,6 +129,8 @@ export function createInstanceRoutes(deps: InstanceRouteDeps): RouteHandler {
return json(res, 200, { instances: hidden.map(([instanceId, entry]) => ({ instanceId, driverKind: entry.driver, displayName: entry.displayName ?? BUILT_IN_DRIVERS.find((driver) => driver.driverKind === entry.driver)?.metadata.displayName ?? instanceId })) });
}
if (method === "GET" && path === "/api/instances") {
+ // A member reads what picking a model and steering a turn need; a rescan and a fresh read stay the admin's.
+ if (auth.kind === "session" && !auth.scopes.includes("admin")) return json(res, 200, { instances: memberInstances(await describeInstances()) });
// Rescan PATH: Windows never pushes PATH changes into a live process, so a CLI installed since launch stays invisible.
resetPathCache();
if (url.searchParams.get("fresh") === "1") registry.forgetSnapshots();