Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
feat(minimax): MiniMax's own thinking controls, and never a reasoning_effort it refuses
David Neyra903819e8bfce
diff --git a/server/drivers/minimax.test.ts b/server/drivers/minimax.test.tsindex 70146b7f30..12675e72d9 100644--- a/server/drivers/minimax.test.ts+++ b/server/drivers/minimax.test.ts@@ -41,14 +41,42 @@ describe("MinimaxDriver", () => {expect(MinimaxDriver.models).toEqual({default: "MiniMax-M3",options: [- { id: "MiniMax-M3.1-Flash", label: "MiniMax M3.1 Flash", contextWindow: 1_000_000, custom: true },- { id: "MiniMax-M3", label: "MiniMax M3", contextWindow: 1_000_000, custom: true },+ {+ id: "MiniMax-M3.1-Flash",+ label: "MiniMax M3.1 Flash",+ contextWindow: 1_000_000,+ custom: true,+ variants: [+ { id: "low", label: "Low" },+ { id: "medium", label: "Medium" },+ { id: "high", label: "High" },+ { id: "xhigh", label: "Xhigh" },+ { id: "max", label: "Max" },+ ],+ },+ {+ id: "MiniMax-M3",+ label: "MiniMax M3",+ contextWindow: 1_000_000,+ custom: true,+ variants: [{ id: "off", label: "No thinking" }],+ },{ id: "MiniMax-M2.7", label: "MiniMax M2.7", contextWindow: 204_800, custom: true },{ id: "MiniMax-M2.7-highspeed", label: "MiniMax M2.7 Highspeed", contextWindow: 204_800, custom: true },],});});+ it("offers MiniMax's own thinking controls, and no other model any", () => {+ expect(MinimaxDriver.models.options.map((option) => [option.id, option.variants?.map((choice) => choice.id)]))+ .toEqual([+ ["MiniMax-M3.1-Flash", ["low", "medium", "high", "xhigh", "max"]],+ ["MiniMax-M3", ["off"]],+ ["MiniMax-M2.7", undefined],+ ["MiniMax-M2.7-highspeed", undefined],+ ]);+ });+it("flags every catalog model custom so the picker's custom-access pane lists them", () => {expect(MinimaxDriver.metadata.access).toBe("custom");expect(MinimaxDriver.models.options.every((option) => option.custom === true)).toBe(true);@@ -200,6 +228,74 @@ describe("MinimaxDriver", () => {}});+ /** Runs one turn and returns every chat body the driver sent, in order. */+ async function chatBodies(+ model: string,+ variant?: string,+ answer?: (call: number) => Response,+ ): Promise<Array<Record<string, unknown>>> {+ const bodies: Array<Record<string, unknown>> = [];+ vi.stubGlobal("fetch", vi.fn(async (_input: string | URL | Request, init?: RequestInit) => {+ bodies.push(JSON.parse(String(init?.body)) as Record<string, unknown>);+ return answer?.(bodies.length)+ ?? new Response('data: {"choices":[{"delta":{"content":"hello"}}]}\n' + "data: [DONE]\n", { headers: { "content-type": "text/event-stream" } });+ }));+ const instance = await MinimaxDriver.create({+ instanceId: "minimax-thinking",+ displayName: "MiniMax",+ enabled: true,+ config: MinimaxDriver.defaultConfig(),+ environment: { MINIMAX_API_KEY: "secret" },+ });+ const recorder = recordEvents(instance.adapter);+ try {+ await instance.adapter.sendTurn({ threadId: "thinking", text: "hi", model, ...(variant ? { variant } : {}) });+ expect(await recorder.until((event) => event.type === "turn.completed")).toMatchObject({ ok: true });+ return bodies;+ } finally {+ recorder.stop();+ await instance.dispose();+ }+ }++ it("sends the picked thinking depth as MiniMax's own reasoning_effort", async () => {+ const bodies = await chatBodies("MiniMax-M3.1-Flash", "high");+ expect(bodies[0]).toMatchObject({ model: "MiniMax-M3.1-Flash", reasoning_effort: "high" });+ expect(bodies[0]).not.toHaveProperty("thinking");+ });++ it("turns thinking off on MiniMax-M3 with MiniMax's own switch", async () => {+ const bodies = await chatBodies("MiniMax-M3", "off");+ expect(bodies[0]).toMatchObject({ model: "MiniMax-M3", thinking: { type: "disabled" } });+ expect(bodies[0]).not.toHaveProperty("reasoning_effort");+ });++ it("sends no thinking control when none was picked", async () => {+ const bodies = await chatBodies("MiniMax-M3.1-Flash");+ expect(bodies[0]).not.toHaveProperty("reasoning_effort");+ expect(bodies[0]).not.toHaveProperty("thinking");+ });++ it("sends nothing MiniMax would answer 400 to", async () => {+ const flash = await chatBodies("MiniMax-M3.1-Flash", "off");+ expect(flash[0]).not.toHaveProperty("reasoning_effort");+ expect(flash[0]).not.toHaveProperty("thinking");+ const older = await chatBodies("MiniMax-M2.7", "high");+ expect(older[0]).not.toHaveProperty("reasoning_effort");+ expect(older[0]).not.toHaveProperty("thinking");+ });++ it("never sends reasoning_effort none, which MiniMax refuses", async () => {+ // The provider answers as OpenAI does when tools and reasoning meet: the runtime drops to+ // reasoning-off, and MiniMax has no `reasoning_effort: "none"` to answer that with.+ const bodies = await chatBodies("MiniMax-M3", undefined, (call) => call === 1+ ? new Response(JSON.stringify({ error: { message: "Function tools with reasoning_effort are not supported in /v1/chat/completions. To use function tools, use /v1/responses or set reasoning_effort to 'none'." } }), { status: 400, headers: { "content-type": "application/json" } })+ : new Response('data: {"choices":[{"delta":{"content":"hello"}}]}\n' + "data: [DONE]\n", { headers: { "content-type": "text/event-stream" } }));+ expect(bodies.length).toBeGreaterThan(1);+ for (const body of bodies) expect(body).not.toHaveProperty("reasoning_effort");+ expect(bodies.at(-1)).toMatchObject({ thinking: { type: "disabled" } });+ });+it("smoke: offers ask_user and returns the person's reply verbatim", async () => {const askBody = 'data: {"choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"id":"ask1","type":"function","function":{"name":"ask_user","arguments":'+ JSON.stringify(JSON.stringify({ questions: [{ question: "Ship the fixture?", options: [{ label: "Yes" }, { label: "No" }] }] }))diff --git a/server/drivers/minimax.ts b/server/drivers/minimax.tsindex 705f87c6b4..5b3cbf6095 100644--- a/server/drivers/minimax.ts+++ b/server/drivers/minimax.ts@@ -4,24 +4,52 @@ import { homedir } from "node:os";import { join } from "node:path";import { z } from "zod";-import type { ModelCatalog, ProviderDriver } from "../contracts.ts";+import { titleCaseModelId, type ModelCatalog, type ProviderDriver } from "../contracts.ts";import { createOpenAIChatRuntime } from "./openai-chat.ts";const DRIVER_KIND = "minimax";const API_KEY_ENV = "MINIMAX_API_KEY";const DEFAULT_URL = "https://api.minimax.io/v1";const CN_URL = "https://api.minimaxi.com/v1";+const FLASH_MODEL = "MiniMax-M3.1-Flash";+const M3_MODEL = "MiniMax-M3";+/** The thinking depths MiniMax's own API takes for `reasoning_effort`; it answers 400 to any other value. */+const THINKING_DEPTHS = ["low", "medium", "high", "xhigh", "max"];const MODELS: ModelCatalog = {- default: "MiniMax-M3",+ default: M3_MODEL,// `custom: true` is load-bearing: a custom-access engine's picker pane lists only custom-flagged models.options: [- { id: "MiniMax-M3.1-Flash", label: "MiniMax M3.1 Flash", contextWindow: 1_000_000, custom: true },- { id: "MiniMax-M3", label: "MiniMax M3", contextWindow: 1_000_000, custom: true },+ {+ id: FLASH_MODEL,+ label: "MiniMax M3.1 Flash",+ contextWindow: 1_000_000,+ custom: true,+ // MiniMax-M3.1-Flash always thinks; only its depth is a choice.+ variants: THINKING_DEPTHS.map((id) => ({ id, label: titleCaseModelId(id, /[-_ ]+/) })),+ },+ {+ id: M3_MODEL,+ label: "MiniMax M3",+ contextWindow: 1_000_000,+ custom: true,+ // MiniMax-M3 answers straight when its thinking is off; its depth is not a choice.+ variants: [{ id: "off", label: "No thinking" }],+ },{ id: "MiniMax-M2.7", label: "MiniMax M2.7", contextWindow: 204_800, custom: true },{ id: "MiniMax-M2.7-highspeed", label: "MiniMax M2.7 Highspeed", contextWindow: 204_800, custom: true },],};+/** MiniMax's own thinking controls: `reasoning_effort` sets the depth on MiniMax-M3.1-Flash, and+ * `thinking: { type: "disabled" }` answers straight on MiniMax-M3. The API answers 400 to+ * `reasoning_effort: "none"` and to a disabled thinking on MiniMax-M3.1-Flash, which always thinks. */+function thinkingParams(model: string, variant: string | undefined): Record<string, unknown> {+ if (!variant) return {};+ if (model === FLASH_MODEL) return THINKING_DEPTHS.includes(variant) ? { reasoning_effort: variant } : {};+ if (model === M3_MODEL) return variant === "off" ? { thinking: { type: "disabled" } } : {};+ return {};+}+export interface MinimaxConfig {tools?: boolean;/** An explicit instance or environment URL; absent uses mmx-cli's endpoint, then the international API. */@@ -110,13 +138,18 @@ export const MinimaxDriver: ProviderDriver<MinimaxConfig> = {apiUrl,tools: input.config.tools,models: () => models,- requestBody: (model, messages, stream) => ({+ modelVariants: true,+ requestBody: (model, messages, stream, variant) => ({model,messages,stream,reasoning_split: true,+ ...thinkingParams(model, variant),stream_options: stream ? { include_usage: true } : undefined,}),+ // MiniMax has no `reasoning_effort: "none"`: its own switch turns thinking off, and on+ // MiniMax-M3.1-Flash, which always thinks, there is nothing to send.+ reasoningOffBody: (model) => (model === M3_MODEL ? { thinking: { type: "disabled" } } : {}),httpErrorLabel: "MiniMax",missingKeyError: `no MiniMax key — set ${API_KEY_ENV} or run mmx auth login --api-key …`,unavailableReason: `no MiniMax API key — run mmx auth login --api-key … or set ${API_KEY_ENV}`,diff --git a/server/drivers/openai-chat.ts b/server/drivers/openai-chat.tsindex 86c6e718ea..a606395efd 100644--- a/server/drivers/openai-chat.ts+++ b/server/drivers/openai-chat.ts@@ -108,6 +108,10 @@ interface RuntimeOptions<Config> {reasoning?: boolean;/** Cerebras rejects `reasoning_content` and takes `reasoning`. */reasoningReplayField?: "reasoning_content" | "reasoning";+ /** What to send when a turn drops to reasoning-off, for a provider whose API has no+ * `reasoning_effort: "none"`: its own switch, or `{}` to leave the model thinking as it is.+ * Unset keeps OpenAI's default. */+ reasoningOffBody?: (model: string) => Record<string, unknown>;contentText?: (content: unknown) => string;billing?: "metered";includeUsageInCompleted?: boolean;@@ -285,7 +289,7 @@ export function createOpenAIChatRuntime<Config>(options: RuntimeOptions<Config>)? responsesRequest({ model: served, messages, tools, replay: (message) => responseOutputs.get(message), summaries: routes.summaries(model), effort: options.requestBody(served, messages, stream, variant).reasoning_effort }): {...options.requestBody(served, messages, stream, variant),- ...(route === "chat-reasoning-off" ? { reasoning_effort: "none" } : {}),+ ...(route === "chat-reasoning-off" ? (options.reasoningOffBody?.(served) ?? { reasoning_effort: "none" }) : {}),...(tools.length ? { tools } : {}),});const send = options.timeoutMs > FETCH_LIMIT_MS ? fetchPastLimit : fetch;