Skip to content

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

Decision model: a picked custom endpoint decides alone, and only when picked

Krishna Dobhal1edb584ae8cd
diff --git a/docs/decision-model.md b/docs/decision-model.md
index 13d1c08a89..265ac77296 100644
--- a/docs/decision-model.md
+++ b/docs/decision-model.md
@@ -14,16 +14,20 @@ Cloudflare Workers AI card, the Jev/OpenRouter/Custom endpoint picker under
**Another key**, for OpenRouter the model, for a custom endpoint its base URL,
model ID and protocol, one master switch, each key with **Save** and
**Test**, and a switch for room routing (**Who answers in rooms**). Each
-provider keeps its own key, but picking a provider does not choose whose key
-decides: the fixed order below does. To use Workers AI or OpenRouter while a
+provider keeps its own key. Picking **Custom endpoint** makes it the only one
+that decides; picking Jev or OpenRouter does not choose whose key decides: the
+fixed order below does. To use Workers AI or OpenRouter while a
Jev key is saved, clear the Jev key (an `OMB_JEV_API_KEY` in the environment
replaces the saved one, so remove it too). OpenRouter needs no key here when
you already saved one under **Settings → API keys**: the decision model uses
that one.
-With several keys saved, one fixed order picks whose key decides: your own
-custom endpoint, then your own Jev key, then your own Workers AI key, then
-Cloud's included decisions, then OpenRouter.
+With **Custom endpoint** picked, only the custom endpoint decides, and nothing
+does until its base URL and key are saved; any other key saved stays unused
+until another provider is picked. Otherwise, with several keys saved, one fixed
+order picks whose key decides: your own Jev key, then your own Workers AI key,
+then Cloud's included decisions, then OpenRouter. A custom endpoint's key is
+not part of that order.
## Cloudflare Workers AI (free tier)
diff --git a/server/decider/custom.test.ts b/server/decider/custom.test.ts
index d18453ab09..28d94d3094 100644
--- a/server/decider/custom.test.ts
+++ b/server/decider/custom.test.ts
@@ -97,12 +97,21 @@ describe("a custom decision endpoint", () => {
expect(deciderAccount(local)).toMatchObject({ provider: "custom", api: "http://127.0.0.1:8080/v1" });
});
- it("decides before a saved Jev key, and Settings sees its model, protocol and address but not the key", () => {
+ it("decides only while it is the chosen provider, and Settings sees its model, protocol and address but not the key", () => {
const both: AppConfig = { decider: { ...ON("decisions").decider, key: "jev-key" } };
expect(deciderAccount(both)?.provider).toBe("custom");
const described = describeDecider(both);
expect(described).toMatchObject({ provider: "custom", model: MODEL, api: "decisions", baseUrl: BASE, configured: true });
expect(JSON.stringify(described)).not.toContain(KEY);
+ const backToJev: AppConfig = { decider: { ...both.decider, provider: "jev" } };
+ expect(deciderAccount(backToJev)?.provider).toBe("jev");
+ expect(describeDecider(backToJev).provider).toBe("jev");
+ });
+
+ it("stays chosen while it is being set up, even with another key saved, and lends that key nothing", () => {
+ const settingUp: AppConfig = { decider: { enabled: true, provider: "custom", key: "jev-key" } };
+ expect(deciderAccount(settingUp)).toBeNull();
+ expect(describeDecider(settingUp)).toMatchObject({ provider: "custom", configured: false, model: "", baseUrl: "" });
});
it("tests a saved key before keeping it, and needs a usable base URL with it", () => {
diff --git a/server/decider/index.ts b/server/decider/index.ts
index e0e3578ff7..379b1a27f4 100644
--- a/server/decider/index.ts
+++ b/server/decider/index.ts
@@ -51,11 +51,13 @@ export function deciderApi(cfg: AppConfig): OpenRouterApi {
return cfg.decider.openrouterApi === "decisions" ? "decisions" : "chat";
}
-/** In order: the person's own gateway, their own Jev key, their own Workers AI key (Clef), Cloud's included relay (only for seams it
- * accepts), the OpenRouter LLM fallback, nothing. */
+/** A chosen custom gateway decides alone, or nothing does until it is set up. Otherwise, in order: the person's own Jev
+ * key, their own Workers AI key (Clef), Cloud's included relay (only for seams it accepts), the OpenRouter LLM fallback,
+ * nothing. */
export function deciderAccount(cfg: AppConfig, seam?: DeciderSeam): HelperAccount | null {
+ if (cfg.decider?.provider === "custom") return customAccount(cfg);
const jev = jevAccount(cfg);
- const candidates = [customAccount(cfg), jev, workersAiAccount(cfg), jev?.included ? null : includedAccount(), openrouterAccount(cfg)];
+ const candidates = [jev, workersAiAccount(cfg), jev?.included ? null : includedAccount(), openrouterAccount(cfg)];
return candidates.find((account): account is HelperAccount => Boolean(account) && !(account!.included && seam && !relaySeam(seam))) ?? null;
}