Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(server): move keep-warm eligibility out of index.ts
koeriaf8bc11d08622
diff --git a/server/claude-endpoints.test.ts b/server/claude-endpoints.test.tsindex 192d18b609..b844dfc684 100644--- a/server/claude-endpoints.test.ts+++ b/server/claude-endpoints.test.ts@@ -7,6 +7,7 @@ import {claudeEndpointUpdateSchema,claudeEndpointInfo,claudeEndpointKeepWarmOptIn,+ cacheKeepWarmUnavailableReason,isClaudeEndpoint,newClaudeEndpoint,updateClaudeEndpoint,@@ -145,6 +146,16 @@ describe("custom Claude endpoint", () => {expect(claudeEndpointKeepWarmOptIn(reverted.instances[off.instanceId])).toBe(false);expect((reverted.instances[off.instanceId].config as Record<string, unknown>)).not.toHaveProperty("cacheKeepWarm");expect(claudeEndpointKeepWarmOptIn(reverted.instances.claude)).toBe(false);+ expect(claudeEndpointKeepWarmOptIn(undefined)).toBe(false);++ const refusal = "keep-warm runs only on a Claude subscription sign-in or an endpoint opted in with a verified one-hour cache";+ const opted = on.instances[on.instanceId];+ const plain = off.instances[off.instanceId];+ expect(cacheKeepWarmUnavailableReason("subscription", plain)).toBeNull();+ expect(cacheKeepWarmUnavailableReason("subscription", undefined)).toBeNull();+ expect(cacheKeepWarmUnavailableReason("api", opted)).toBeNull();+ expect(cacheKeepWarmUnavailableReason("api", plain)).toBe(refusal);+ expect(cacheKeepWarmUnavailableReason(undefined, undefined)).toBe(refusal);});it("keeps a discovered catalog when only a model mapping changes", () => {diff --git a/server/claude-endpoints.ts b/server/claude-endpoints.tsindex 14e023a9c1..fe556ebdce 100644--- a/server/claude-endpoints.ts+++ b/server/claude-endpoints.ts@@ -67,7 +67,18 @@ export function isClaudeEndpoint(entry: InstanceConfig | undefined): boolean {/** True when the person opted this custom endpoint into prompt-cache keep-warm by vouching for its one-hour cache. */export function claudeEndpointKeepWarmOptIn(entry: InstanceConfig | undefined): boolean {- return isClaudeEndpoint(entry) && rawConfig(entry).cacheKeepWarm === true;+ return entry !== undefined && isClaudeEndpoint(entry) && rawConfig(entry).cacheKeepWarm === true;+}++/** Null when keep-warm may run; otherwise the reason it may not. */+export function cacheKeepWarmUnavailableReason(+ billing: string | undefined,+ entry: InstanceConfig | undefined,+): string | null {+ // A metered API key's cache lives five minutes by default; a custom endpoint the person+ // vouched for with a verified one-hour cache may still opt in (instance-level, off by default).+ if (billing === "subscription" || claudeEndpointKeepWarmOptIn(entry)) return null;+ return "keep-warm runs only on a Claude subscription sign-in or an endpoint opted in with a verified one-hour cache";}export type { ClaudeEndpointInfo };diff --git a/server/index.ts b/server/index.tsindex b63d3e6c50..d25ab2ad96 100644--- a/server/index.ts+++ b/server/index.ts@@ -145,8 +145,7 @@ import {type Runtime,} from "./container-computer.ts";import { containerComputerMcp } from "./local-vm-box.ts";-import { attachedFileLine, attachForTurn, saveBotAttachment } from "./bot-attachment.ts"; import { attachNotFound } from "./attach-file-hint.ts";-import { claudeEndpointKeepWarmOptIn } from "./claude-endpoints.ts";+import { attachedFileLine, attachForTurn, saveBotAttachment } from "./bot-attachment.ts"; import { attachNotFound } from "./attach-file-hint.ts"; import { cacheKeepWarmUnavailableReason } from "./claude-endpoints.ts";import {cacheUntilConfigChanges,ensureDirs,@@ -5173,11 +5172,7 @@ const cacheKeepWarm = createCacheKeepWarm({const instance = registry.get(instanceId);if (!instance?.adapter.cacheKeepWarm) return "this engine cannot keep its cache warm";if (policyModelRefusal(instance)) return "this engine is not allowed here";- // A metered API key's cache lives five minutes by default; a custom endpoint the person- // vouched for with a verified one-hour cache may still opt in (instance-level, off by default).- if (registry.lastSnapshot(instanceId)?.billing !== "subscription" && !claudeEndpointKeepWarmOptIn(instanceConfigs(cfg)[instanceId]))- return "keep-warm runs only on a Claude subscription sign-in or an endpoint opted in with a verified one-hour cache";- return null;+ return cacheKeepWarmUnavailableReason(registry.lastSnapshot(instanceId)?.billing, instanceConfigs(cfg)[instanceId]);},busy: ({ threadId, botId }) => threadBusy(botId, threadId) || botHasActiveTurn(botId) || Boolean(store.groupByThread(threadId)?.busyBotId),overBudget: () => spendState(cfg, DATA_DIR)?.exceeded === true || usageCapGate.refusal(undefined, false) !== null,