Skip to content

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

Keep Gemini's engines from dropping tools with x-* schema keys or local $refs

sumingwang2336d28d7a72702
diff --git a/server/tool-schema-profile.test.ts b/server/tool-schema-profile.test.ts
index 878209cbae..54c6461a7c 100644
--- a/server/tool-schema-profile.test.ts
+++ b/server/tool-schema-profile.test.ts
@@ -302,3 +302,55 @@ describe("OpenMausBot's own tools", () => {
}
});
});
+
+describe("cleaning a tool schema for Gemini's engines", () => {
+ const GEMINI = toolSchemaProfile("gemini")!;
+
+ it("strips an x-* extension so the engine keeps the tool", () => {
+ const schema = {
+ type: "object",
+ properties: {
+ deviceType: { type: "string", enum: ["MOBILE", "DESKTOP"], "x-google-enum-descriptions": ["A phone.", "A computer."] },
+ },
+ };
+ const fit = fitToolSchema(schema, GEMINI);
+ if (fit.outcome !== "kept") throw new Error(`expected kept, got ${fit.outcome}`);
+ expect(JSON.stringify(fit.schema)).not.toContain("x-google");
+ expect((fit.schema.properties as Json).deviceType).toEqual({ type: "string", enum: ["MOBILE", "DESKTOP"] });
+ });
+
+ it("inlines a local $ref and drops the definitions so the engine keeps the tool", () => {
+ const schema = {
+ type: "object",
+ $defs: { Target: { type: "object", properties: { id: { type: "string" } }, required: ["id"] } },
+ properties: { target: { $ref: "#/$defs/Target", description: "Where it goes." } },
+ };
+ const fit = fitToolSchema(schema, GEMINI);
+ if (fit.outcome !== "kept") throw new Error(`expected kept, got ${fit.outcome}`);
+ expect((fit.schema.properties as Json).target).toEqual({
+ type: "object", properties: { id: { type: "string" } }, required: ["id"], description: "Where it goes.",
+ });
+ expect(fit.schema.$defs).toBeUndefined();
+ });
+
+ it("keeps a schema that only x-* extensions push over the limit whole instead of trimming it", () => {
+ const long = Array.from({ length: 50 }, (_, index) => `Choice number ${index} spelled out at greater length`);
+ const schema = {
+ type: "object",
+ properties: {
+ mode: { type: "string", enum: ["one", "two"], "x-google-enum-descriptions": ["First mode.", "Second mode."] },
+ sizes: { type: "string", enum: Array.from({ length: 50 }, (_, index) => `size-${index}`), "x-google-enum-descriptions": long },
+ },
+ };
+ expect(schemaBytes(schema)).toBeGreaterThan(GEMINI.maxSchemaBytes);
+ const fit = fitToolSchema(schema, GEMINI);
+ if (fit.outcome !== "kept") throw new Error(`expected kept, got ${fit.outcome}`);
+ expect(fit.bytes).toBeLessThanOrEqual(GEMINI.maxSchemaBytes);
+ expect(JSON.stringify(fit.schema)).not.toContain("x-google");
+ });
+
+ it("leaves a schema without those keywords as it was", () => {
+ const schema = { type: "object", properties: { id: { type: "string", description: "The id." } }, required: ["id"] };
+ expect(fitToolSchema(schema, GEMINI)).toEqual({ outcome: "kept", schema, bytes: schemaBytes(schema) });
+ });
+});
diff --git a/server/tool-schema-profile.ts b/server/tool-schema-profile.ts
index e142148066..b99d3f94ac 100644
--- a/server/tool-schema-profile.ts
+++ b/server/tool-schema-profile.ts
@@ -327,9 +327,22 @@ export type SchemaFit =
| { outcome: "trimmed" | "loosened" | "minimal"; schema: Json; bytes: number; from: number }
| { outcome: "dropped"; bytes: number; from: number };
+/** The Gemini Schema subset the Antigravity and Gemini CLIs convert: an `x-*` extension such as
+ * `x-google-enum-descriptions`, or a local `$ref` it cannot resolve, makes the engine drop the whole tool from its call
+ * registry with no refusal, the way an oversized schema does: the model still reads the tool's definition, but every
+ * call fails as an unknown tool. Cleaning the schema before it is fitted keeps those tools registered; keywords the
+ * engine accepts pass through untouched. A schema whose refs do not all inline (a cycle, a ref that resolves to
+ * nothing) keeps its refs as they were rather than half-inline them. */
+function geminiSafeSchema(schema: Json): Json {
+ const clean = structuredClone(schema);
+ stripAnnotations(clean);
+ const inlined = inlineRefs(clean);
+ return inlined && !JSON.stringify(inlined).includes('"$ref"') ? inlined : clean;
+}
+
/** Least loss first, stopping at the first form that fits. */
export function fitToolSchema(schema: Json, profile: ToolSchemaProfile): SchemaFit {
- const typed = profile.id === "moonshot" ? withTypedMixedEnums(schema) : schema;
+ const typed = profile.id === "moonshot" ? withTypedMixedEnums(schema) : profile.id === "gemini" ? geminiSafeSchema(schema) : schema;
const measured = profile.measureInlined ? inlineRefs(typed) : typed;
const from = schemaBytes(measured ?? typed);
if (measured && fits(measured, profile)) return { outcome: "kept", schema: typed, bytes: from };