Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(server): let a custom Claude endpoint with a verified one-hour cache opt into keep-warm
koeriad5d7a454f372
diff --git a/server/claude-endpoints.test.ts b/server/claude-endpoints.test.tsindex 8e48b3d2f3..192d18b609 100644--- a/server/claude-endpoints.test.ts+++ b/server/claude-endpoints.test.ts@@ -6,6 +6,7 @@ import {claudeEndpointSchema,claudeEndpointUpdateSchema,claudeEndpointInfo,+ claudeEndpointKeepWarmOptIn,isClaudeEndpoint,newClaudeEndpoint,updateClaudeEndpoint,@@ -99,6 +100,7 @@ describe("custom Claude endpoint", () => {expect(info).toEqual({baseUrl: BASE.baseUrl.replace(/\/$/u, ""),models: ["deepseek-chat"],+ cacheKeepWarm: false,tokenSaved: true,opusModel: "", sonnetModel: "", haikuModel: "", smallFastModel: "",});@@ -130,6 +132,21 @@ describe("custom Claude endpoint", () => {expect(updated.instances.claude).toEqual(instances.claude);});+ it("opts a verified one-hour-cache endpoint into keep-warm, on by explicit choice only", () => {+ const off = newClaudeEndpoint(cfg(), BASE);+ expect(claudeEndpointKeepWarmOptIn(off.instances[off.instanceId])).toBe(false);+ const on = newClaudeEndpoint(cfg(), { ...BASE, cacheKeepWarm: true });+ expect(claudeEndpointKeepWarmOptIn(on.instances[on.instanceId])).toBe(true);+ expect(claudeEndpointInfo(on.instances[on.instanceId]).cacheKeepWarm).toBe(true);+ // An update can turn it on and back off; other account entries never opt in.+ const edited = updateClaudeEndpoint({ instances: off.instances }, off.instanceId, { cacheKeepWarm: true });+ expect(claudeEndpointKeepWarmOptIn(edited.instances[off.instanceId])).toBe(true);+ const reverted = updateClaudeEndpoint({ instances: edited.instances }, off.instanceId, { cacheKeepWarm: false });+ 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);+ });+it("keeps a discovered catalog when only a model mapping changes", () => {const { instanceId, instances } = newClaudeEndpoint(cfg(), { ...BASE, model: undefined });(instances[instanceId].config as { endpointModels: string[] }).endpointModels = ["model-a", "model-b"];diff --git a/server/claude-endpoints.ts b/server/claude-endpoints.tsindex e74d35eeba..14e023a9c1 100644--- a/server/claude-endpoints.ts+++ b/server/claude-endpoints.ts@@ -29,6 +29,8 @@ export const claudeEndpointSchema = z.object({sonnetModel: optionalModel.optional(),haikuModel: optionalModel.optional(),smallFastModel: optionalModel.optional(),+ /** The person vouches this endpoint serves a verified one-hour prompt cache. */+ cacheKeepWarm: z.boolean().optional(),}).strict();export const claudeEndpointUpdateSchema = z.object({@@ -41,6 +43,7 @@ export const claudeEndpointUpdateSchema = z.object({sonnetModel: optionalModel.optional(),haikuModel: optionalModel.optional(),smallFastModel: optionalModel.optional(),+ cacheKeepWarm: z.boolean().optional(),}).strict().refine((value) => Object.keys(value).length > 0, "No settings supplied");type EndpointFields = z.infer<typeof claudeEndpointUpdateSchema>;@@ -62,6 +65,11 @@ export function isClaudeEndpoint(entry: InstanceConfig | undefined): boolean {return entry?.driver === "claudeAgent" && Array.isArray(rawConfig(entry).endpointModels) && rawConfig(entry).bedrock !== true;}+/** 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;+}+export type { ClaudeEndpointInfo };/** What the settings UI may know about an endpoint: where it points and which models, never the token. */@@ -71,6 +79,7 @@ export function claudeEndpointInfo(entry: InstanceConfig): ClaudeEndpointInfo {return {baseUrl: environment.ANTHROPIC_BASE_URL ?? "",models: Array.isArray(config.endpointModels) ? [...config.endpointModels] : [],+ cacheKeepWarm: config.cacheKeepWarm === true,tokenSaved: Boolean(environment.ANTHROPIC_AUTH_TOKEN || environment.ANTHROPIC_API_KEY),opusModel: environment.ANTHROPIC_DEFAULT_OPUS_MODEL ?? "",sonnetModel: environment.ANTHROPIC_DEFAULT_SONNET_MODEL ?? "",@@ -136,6 +145,7 @@ export function newClaudeEndpoint(cfg: AppConfig, body: z.infer<typeof claudeEndconfigDir: join(DATA_DIR, "providers", instanceId),requireApiKey: true,endpointModels: body.model ? endpointModels(body) : officialModels(false),+ ...(body.cacheKeepWarm === true ? { cacheKeepWarm: true } : {}),},environment: endpointEnvironment(body.baseUrl, body.token, body),};@@ -164,11 +174,16 @@ export function updateClaudeEndpoint(cfg: AppConfig, instanceId: string, body: E}const secret = body.token ?? entry.environment?.ANTHROPIC_AUTH_TOKEN ?? entry.environment?.ANTHROPIC_API_KEY;if (!secret) throw Object.assign(new Error("Enter the endpoint's token."), { status: 400 });+ const config: Record<string, unknown> = { ...rawConfig(entry), endpointModels: fields.model && (body.model !== undefined || TIERS.some(([field]) => body[field] !== undefined)) ? endpointModels(fields) : saved.models };+ if (body.cacheKeepWarm !== undefined) {+ if (body.cacheKeepWarm) config.cacheKeepWarm = true;+ else delete config.cacheKeepWarm;+ }instances[instanceId] = {...entry,...(fields.displayName ? { displayName: fields.displayName } : {}),environment: endpointEnvironment(address, secret, fields),- config: { ...rawConfig(entry), endpointModels: fields.model && (body.model !== undefined || TIERS.some(([field]) => body[field] !== undefined)) ? endpointModels(fields) : saved.models },+ config,};return { instances };}diff --git a/server/index.ts b/server/index.tsindex 2d5930c9d1..b63d3e6c50 100644--- a/server/index.ts+++ b/server/index.ts@@ -146,6 +146,7 @@ import {} 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 {cacheUntilConfigChanges,ensureDirs,@@ -5172,8 +5173,10 @@ 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: pinging it costs more than the re-write it saves.- if (registry.lastSnapshot(instanceId)?.billing !== "subscription") return "keep-warm runs only on a Claude subscription sign-in";+ // 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;},busy: ({ threadId, botId }) => threadBusy(botId, threadId) || botHasActiveTurn(botId) || Boolean(store.groupByThread(threadId)?.busyBotId),diff --git a/shared/claude-endpoint.ts b/shared/claude-endpoint.tsindex 98b32e2d55..2dbcb61256 100644--- a/shared/claude-endpoint.ts+++ b/shared/claude-endpoint.ts@@ -2,6 +2,7 @@export interface ClaudeEndpointInfo {baseUrl: string;models: string[];+ cacheKeepWarm: boolean;tokenSaved: boolean;opusModel: string;sonnetModel: string;