Open-source AI coworkers that each get a computer of their own: a browser, files and tools, with every action decided before it happens and recorded after. Bring any AG-UI agent.
Use the model name this Bot was given, not the whitespace around it (#593)
Vaibhav Zopeeb3253000232
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 6e5f737a..c0db3aba 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -8,6 +8,16 @@ Newest first. `Unreleased` is what is on `main` and not yet tagged.## Unreleased+### The proof-of-concept Bot reads a model name set with whitespace around it++A `BOT_MODEL` carrying a leading space reached this Bot as it was written. Its startup check refuses+`gpt-5.6-*`, which rejects function tools on the API this Bot speaks, and that check matches from the+start of the name, so a padded one walked past it: the Bot started, reported healthy, and answered+nothing at all on the first turn that used a tool. An empty value was read the same way and asked the+provider for a model with no name. Both now fall back to the default, and the name is used trimmed.+`.env` was never a route to this — Compose, Bun and the desktop shell each strip the value first — so+it reached only deployments that set the variable directly, such as a Kubernetes manifest or+`docker run -e`.### Pasting into a Bot's browser works on a layout that does not write Latin lettersWhile somebody drives a Bot's browser, Ctrl+V or Cmd+V is left to the local page so its paste eventdiff --git a/agent-bot/src/index.ts b/agent-bot/src/index.tsindex 6be314ed..b470ac93 100644--- a/agent-bot/src/index.ts+++ b/agent-bot/src/index.ts@@ -5,7 +5,12 @@ import OpenAI from "openai";import { hasManagedAgentToken } from "../../shared/agent-authorisation";import { listenPort } from "../../shared/listen-port";import { toProviderMessages } from "./history";-import { apiKeyOrPlaceholder, keyIsRequired } from "./model-key";+import {+ apiKeyOrPlaceholder,+ keyIsRequired,+ modelIsUnusable,+ modelName,+} from "./model-key";/*** The built-in Bot is an AG-UI HTTP service registered the same way as any customer-provided Bot.@@ -39,7 +44,7 @@ if (!MANAGED_AGENT_TOKEN) {* `gpt-5.6-*` models require the Responses API for tool use and cannot be used by this* chat-completions streaming loop.*/-const MODEL = process.env.BOT_MODEL ?? "gpt-5.5";+const MODEL = modelName(process.env.BOT_MODEL);/** Refuse a model this file cannot use, rather than discover it one tool call at a time.*@@ -51,7 +56,7 @@ const MODEL = process.env.BOT_MODEL ?? "gpt-5.5";** Startup is where a deployment can act on it, which is the same posture as the token check above.*/-if (/^gpt-5\.[6-9]|^gpt-[6-9]/.test(MODEL)) {+if (modelIsUnusable(MODEL)) {console.error(`BOT_MODEL=${MODEL} cannot be used by this Bot. It speaks /v1/chat/completions directly, and ` +"that endpoint refuses function tools for this model, so every tool call would fail with no " +diff --git a/agent-bot/src/model-key.ts b/agent-bot/src/model-key.tsindex 00e2284c..9b219f56 100644--- a/agent-bot/src/model-key.ts+++ b/agent-bot/src/model-key.ts@@ -24,3 +24,11 @@ export function keyIsRequired(baseUrl: string | undefined): boolean {export function apiKeyOrPlaceholder(apiKey: string | undefined): string {return apiKey?.trim() || "no-key-needed";}++export function modelName(configured: string | undefined): string {+ return configured?.trim() || "gpt-5.5";+}++export function modelIsUnusable(model: string): boolean {+ return /^gpt-5\.[6-9]|^gpt-[6-9]/.test(model);+}diff --git a/agent-bot/tests/model-key.test.ts b/agent-bot/tests/model-key.test.tsindex 7ba3f701..3e0c43a7 100644--- a/agent-bot/tests/model-key.test.ts+++ b/agent-bot/tests/model-key.test.ts@@ -1,5 +1,10 @@import { describe, expect, test } from "bun:test";-import { apiKeyOrPlaceholder, keyIsRequired } from "../src/model-key";+import {+ apiKeyOrPlaceholder,+ keyIsRequired,+ modelIsUnusable,+ modelName,+} from "../src/model-key";/*** A named endpoint is a model, and its key belongs to it.@@ -26,3 +31,26 @@ describe("whether a model key is required", () => {expect(apiKeyOrPlaceholder("sk-real")).toBe("sk-real");});});++describe("which model this Bot was told to use", () => {+ test("an unset or empty choice falls back", () => {+ expect(modelName(undefined)).toBe("gpt-5.5");+ expect(modelName("")).toBe("gpt-5.5");+ expect(modelName(" ")).toBe("gpt-5.5");+ });++ test("a padded name is the name", () => {+ expect(modelName(" gpt-5.5 ")).toBe("gpt-5.5");+ });++ test("the models this Bot cannot drive are refused", () => {+ expect(modelIsUnusable("gpt-5.6-terra")).toBe(true);+ expect(modelIsUnusable("gpt-6")).toBe(true);+ expect(modelIsUnusable("gpt-5.5")).toBe(false);+ });++ test("padding does not get one past the guard", () => {+ expect(modelIsUnusable(modelName(" gpt-5.6-terra"))).toBe(true);+ expect(modelIsUnusable(modelName("\tgpt-6 "))).toBe(true);+ });+});diff --git a/tests/agent-bot.test.ts b/tests/agent-bot.test.tsindex 201c72a1..40b9c1e9 100644--- a/tests/agent-bot.test.ts+++ b/tests/agent-bot.test.ts@@ -55,3 +55,16 @@ test("agent-bot still refuses to start without its server token", async () => {expect(exitCode).toBe(1);expect(stderr).toContain("MANAGED_AGENT_TOKEN is not set");});++test("agent-bot refuses a model it cannot drive however the name is spaced", async () => {+ for (const model of ["gpt-5.6-terra", " gpt-5.6-terra", "\tgpt-6 "]) {+ const { exitCode, stderr } = await startBot({+ MANAGED_AGENT_TOKEN: "test-token",+ OPENAI_API_KEY: "sk-test",+ BOT_MODEL: model,+ });++ expect(exitCode).toBe(1);+ expect(stderr).toContain("cannot be used by this Bot");+ }+});