diff --git a/CHANGELOG.md b/CHANGELOG.md index 13d60fd..85aeb2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,24 @@ # Changelog +## 0.55.11 + +### Fixed — GLM goes through Alpha.sh, and a reply cut off mid-reasoning is no longer passed off as the answer + +- `mode:"glm"` now starts at `zai/glm-5.3`, the GLM that every gateway serves + through Alpha.sh first (Z.ai direct is the rescue leg). The list used to be + glm-5 / 5.2 / 5.1 / 5-Turbo, none of which Alpha carries, so `mode:"glm"` + never reached Alpha. `mode:"coding"` uses glm-5.3 in place of glm-5.2. Same + $1.4/$4.4 price, so no budget reserve moves. +- When a reasoning model spends the whole `max_tokens` budget thinking and emits + no content, `blockrun_chat` used to return that reasoning as the reply. A + half-finished analysis read as the model's verdict (seen with `zai/glm-5.3`, + twice), and the "spent the entire max_tokens budget on internal reasoning" + diagnosis never fired. It now fires. A reasoning-only reply that finished + normally still comes back as before. +- Replies carry `served_by`, the upstream the gateway names in + `x-blockrun-served-by` (e.g. `alpha.sh`), on the paths where response headers + reach the client and the gateway sends it. + ## 0.55.10 ### Fixed — chat costs are final only when the response proves a settlement diff --git a/README.md b/README.md index 1c35c0a..defb078 100644 --- a/README.md +++ b/README.md @@ -252,11 +252,11 @@ Package managers have shown install size for decades. Almost no MCP server shows | Profile | Tools | Context | |---------|-------|---------| -| `full` *(default)* | 19 | 14,265 | +| `full` *(default)* | 19 | 14,278 | | `trading` | 8 | 5,471 | | `media` | 7 | 7,016 | -| `research` | 5 | 2,807 | -| `chat` | 3 | 2,155 | +| `research` | 5 | 2,820 | +| `chat` | 3 | 2,168 | Running `--profile trading` instead of the default costs **62% less context** for the same trading workflow. If you only ever ask about markets, that is the single cheapest change you can make. diff --git a/VERSION b/VERSION index f107f5a..8a94fbc 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.55.10 +0.55.11 diff --git a/docs/mcp-schema-overhead.md b/docs/mcp-schema-overhead.md index 97c017d..eecbf19 100644 --- a/docs/mcp-schema-overhead.md +++ b/docs/mcp-schema-overhead.md @@ -16,11 +16,11 @@ Written 2026-09-01, verified against `@modelcontextprotocol/sdk` 1.29.0. Numbers | Profile | Tools | Context | |---------|-------|---------| -| `full` *(default)* | 19 | 14,265 | +| `full` *(default)* | 19 | 14,278 | | `trading` | 8 | 5,471 | | `media` | 7 | 7,016 | -| `research` | 5 | 2,807 | -| `chat` | 3 | 2,155 | +| `research` | 5 | 2,820 | +| `chat` | 3 | 2,168 | Descriptions are ~54% of it, input schemas ~42%. `--profile trading` costs 62% less than the default for the same workflow. diff --git a/package-lock.json b/package-lock.json index 7690698..6e15d52 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@blockrun/mcp", - "version": "0.55.10", + "version": "0.55.11", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@blockrun/mcp", - "version": "0.55.10", + "version": "0.55.11", "license": "MIT", "dependencies": { "@anthropic-ai/sdk": "^0.123.0", diff --git a/package.json b/package.json index e0aaa40..ddd567a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@blockrun/mcp", - "version": "0.55.10", + "version": "0.55.11", "mcpName": "io.github.BlockRunAI/blockrun-mcp", "description": "BlockRun MCP Server - Give your AI agent web search, deep research, prediction markets, and crypto data. Pay per call from a USDC wallet (Solana or Base) or a BlockRun API key.", "type": "module", diff --git a/scripts/verify-prices.ts b/scripts/verify-prices.ts index 59c791d..99b5c65 100644 --- a/scripts/verify-prices.ts +++ b/scripts/verify-prices.ts @@ -316,7 +316,7 @@ const PROBES: Probe[] = [ ["reasoning", "anthropic/claude-opus-5"], // gpt-5.6-sol cut to $4/$20 2026-08-21 ["coding", "anthropic/claude-opus-5"], ["fast", "google/gemini-3.5-flash"], - ["glm", "zai/glm-5.2"], + ["glm", "zai/glm-5.3"], // Alpha-served primary; same $1.4/$4.4 as glm-5.2 ["cheap", "deepseek/deepseek-v4-pro"], ] as Array<[string, string]>).map(([mode, worstMember]) => { const message = "word ".repeat(20_000); // 100k chars diff --git a/src/tools/chat.ts b/src/tools/chat.ts index 213c5a9..17ca0cf 100644 --- a/src/tools/chat.ts +++ b/src/tools/chat.ts @@ -421,6 +421,9 @@ function servedNotes(requested: string, outcome: ChatOutcome, maxTokens: number let text = ""; const served = outcome.servedModel; if (served) fields.served_model = served; + // Which UPSTREAM answered (e.g. alpha.sh vs api.z.ai for zai/glm-5.3), from + // the gateway's x-blockrun-served-by. Only the Response paths carry headers. + if (outcome.servedBy) fields.served_by = outcome.servedBy; if (served && canonicalChatModel(served) !== canonicalChatModel(requested)) { text += `\n\n(Served by ${served} — the gateway answered the requested id ${requested} with this model instead: retired, aliased, or at capacity.)`; } @@ -467,9 +470,9 @@ export function registerChatTool(server: McpServer, budget: BudgetState): void { Notable modes: - mode:"powerful" → Claude Opus 5, Claude Opus 4.8, GPT-5.6-sol, Claude Fable 5 (frontier, 1M context) - mode:"reasoning" → Claude Opus 5, GPT-5.6-sol, Kimi K3, Grok 4.3, deepseek-v4-pro -- mode:"coding" → Claude Opus 5, GPT-5.3-codex, Kimi K3, Grok Build, GLM-5.2 +- mode:"coding" → Claude Opus 5, GPT-5.3-codex, Kimi K3, Grok Build, GLM-5.3 - mode:"cheap" → deepseek-v4-pro, Qwen3.7 Flash, MiniMax M3, Gemini 2.5 Flash, DeepSeek Chat / V4.1 Flash -- mode:"glm" → Zhipu GLM-5 / 5.2 / 5.1 / 5-Turbo (strong at coding) +- mode:"glm" → Zhipu GLM-5.3 (served via Alpha.sh), then GLM-5 / 5.2 / 5.1 / 5-Turbo (strong at coding) - mode:"free" → free models (no cost) Pick directly: model:"anthropic/claude-opus-5.5", model:"openai/gpt-6-sol", model:"xai/grok-4.7", model:"moonshot/kimi-k3", model:"nvidia/gpt-oss-120b" (free). diff --git a/src/utils/chat-stream.ts b/src/utils/chat-stream.ts index b9b84a6..ab49c19 100644 --- a/src/utils/chat-stream.ts +++ b/src/utils/chat-stream.ts @@ -65,6 +65,8 @@ export interface ChatUsage { export interface ChatOutcome { text: string; servedModel: string | null; + /** The upstream that answered, from `x-blockrun-served-by` (e.g. "alpha.sh"); null where no headers reach us. */ + servedBy: string | null; finishReason: string | null; usage: ChatUsage | null; settledUsd: number | null; @@ -141,6 +143,15 @@ export function settledCostFromHeaders(headers: { get(name: string): string | nu * them as final (`cost_is_estimate: false`), because the SDK's counter adds * the signed amount on every paid 2xx. */ +/** + * The gateway's `x-blockrun-served-by`: which upstream actually answered (for + * zai/glm-5.3, "alpha.sh" or the Z.ai rescue leg). A name, never an id. + */ +export function servedByFromHeaders(headers: { get(name: string): string | null } | null | undefined): string | null { + if (typeof headers?.get !== "function") return null; + return headers.get("x-blockrun-served-by")?.trim() || null; +} + export function settlementTxFromHeaders(headers: { get(name: string): string | null } | null | undefined): string | null { if (typeof headers?.get !== "function") return null; if ((headers.get("x-payment-settled") ?? "").trim().toLowerCase() === "false") return null; @@ -244,7 +255,13 @@ class ChatAccumulator { } result(): Omit { - return { text: this.text || this.reasoning, finishReason: this.finishReason, servedModel: this.servedModel, usage: this.usage }; + // Reasoning stands in only for a reply that FINISHED without content. Cut + // at max_tokens with no content, it is thinking that never reached an + // answer: returning it as the reply passed a half-finished analysis off as + // the model's verdict (zai/glm-5.3, 2026-11-17, twice) and skipped the + // max_tokens diagnosis in rejectEmptyLength. Leave text empty so it fires. + const text = this.text || (this.finishReason === "length" ? "" : this.reasoning); + return { text, finishReason: this.finishReason, servedModel: this.servedModel, servedBy: null, usage: this.usage }; } } @@ -377,6 +394,7 @@ export async function streamChatText( const resp = await client.chatCompletionStream(model, messages, options); const settledUsd = settledCostFromHeaders(resp.headers); const settlementTx = settlementTxFromHeaders(resp.headers); + const servedBy = servedByFromHeaders(resp.headers); return afterAccept(async () => { // A provider/route that ignores `stream:true` answers with a plain JSON // completion. Feeding that to the SSE parser would "succeed" with an empty @@ -388,11 +406,11 @@ export async function streamChatText( acc.fold(data); const out = acc.result(); rejectEmptyLength(model, out); - return { ...out, settledUsd, settlementTx }; + return { ...out, servedBy, settledUsd, settlementTx }; } const out = await assembleSseChatStream(resp, idleTimeoutMs); rejectEmptyLength(model, out); - return { ...out, settledUsd, settlementTx }; + return { ...out, servedBy, settledUsd, settlementTx }; }, settlementTx); } diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 150437f..9d87d23 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -236,8 +236,12 @@ export const MODEL_TIERS = { "nvidia/gpt-oss-20b", "nvidia/nemotron-3-super-120b", "nvidia/llama-3.2-11b-vision", "nvidia/nemotron-3-nano-omni-30b-a3b-reasoning", ], - coding: ["anthropic/claude-opus-5", "openai/gpt-5.3-codex", "moonshot/kimi-k3", "xai/grok-build-0.1", "zai/glm-5.2", "qwen/qwen3.7-max", "anthropic/claude-sonnet-5"], - glm: ["zai/glm-5", "zai/glm-5.2", "zai/glm-5.1", "zai/glm-5-turbo"], + // GLM goes through Alpha.sh: zai/glm-5.3 is the one SKU the gateway routes + // there (ALPHA_MODEL_MAP in blockrun model-maps.ts, Z.ai direct as rescue). + // So it leads the glm tier and is coding's GLM member; the rest of the glm + // tier is the Z.ai-direct fallback. Same $1.4/$4.4 as glm-5.2, so no reserve moves. + coding: ["anthropic/claude-opus-5", "openai/gpt-5.3-codex", "moonshot/kimi-k3", "xai/grok-build-0.1", "zai/glm-5.3", "qwen/qwen3.7-max", "anthropic/claude-sonnet-5"], + glm: ["zai/glm-5.3", "zai/glm-5", "zai/glm-5.2", "zai/glm-5.1", "zai/glm-5-turbo"], } as const; export type RoutingMode = keyof typeof MODEL_TIERS; diff --git a/test/chat-stream.test.ts b/test/chat-stream.test.ts index 1f49922..55b7bf4 100644 --- a/test/chat-stream.test.ts +++ b/test/chat-stream.test.ts @@ -305,3 +305,53 @@ test("Solana frame path: a stream that ends with no frames is a post-acceptance (err: Error) => err instanceof AcceptedThenFailedError && /no frames/.test(err.message), ); }); + +// zai/glm-5.3, 2026-11-17: the model spent max_tokens reasoning and never +// produced content. The reasoning fallback handed that unfinished analysis back +// as the reply, so a caller read thinking as a verdict, and the max_tokens +// diagnosis never fired because text was non-empty. +test("reasoning cut off at max_tokens is not passed off as the answer", async () => { + const { streamChatText } = await import("../src/utils/chat-stream.js"); + const sse = [ + `data: ${JSON.stringify({ model: "zai/glm-5.3", choices: [{ delta: { reasoning_content: "Let me carefully analyze…" } }] })}\n\n`, + `data: ${JSON.stringify({ model: "zai/glm-5.3", choices: [{ delta: {}, finish_reason: "length" }] })}\n\n`, + "data: [DONE]\n\n", + ]; + const fakeClient = { + chatCompletionStream: async () => + new Response(new ReadableStream({ + start(c) { for (const s of sse) c.enqueue(enc.encode(s)); c.close(); }, + }), { headers: { "content-type": "text/event-stream" } }), + }; + await assert.rejects( + streamChatText(fakeClient as never, "zai/glm-5.3", [{ role: "user", content: "review" }], {}), + /entire max_tokens budget on internal reasoning/, + ); +}); + +test("reasoning-only reply that finished normally still comes back", async () => { + const out = await assembleSseChatStream(bodyFrom([ + chunk({ choices: [{ delta: { reasoning_content: "the answer, in reasoning" } }] }), + chunk({ choices: [{ delta: {}, finish_reason: "stop" }] }), + ])); + assert.equal(out.text, "the answer, in reasoning"); +}); + +// Which upstream answered: the gateway names it in x-blockrun-served-by. For +// zai/glm-5.3 that is how a caller tells Alpha.sh from the Z.ai rescue leg. +test("x-blockrun-served-by is surfaced as servedBy", async () => { + const { streamChatText } = await import("../src/utils/chat-stream.js"); + const mk = (headers: Record) => ({ + chatCompletionStream: async () => + new Response(new ReadableStream({ + start(c) { + c.enqueue(enc.encode(`data: ${JSON.stringify({ model: "zai/glm-5.3", choices: [{ delta: { content: "ok" }, finish_reason: "stop" }] })}\n\n`)); + c.close(); + }, + }), { headers: { "content-type": "text/event-stream", ...headers } }), + }); + const viaAlpha = await streamChatText(mk({ "x-blockrun-served-by": "alpha.sh" }) as never, "zai/glm-5.3", [{ role: "user", content: "hi" }], {}); + assert.equal(viaAlpha.servedBy, "alpha.sh"); + const none = await streamChatText(mk({}) as never, "zai/glm-5.3", [{ role: "user", content: "hi" }], {}); + assert.equal(none.servedBy, null); +}); diff --git a/test/chat.test.ts b/test/chat.test.ts index 2621675..0302db2 100644 --- a/test/chat.test.ts +++ b/test/chat.test.ts @@ -584,3 +584,12 @@ test("deepseek-v4.1-flash is priced like deepseek-chat and follows it in fast an estimateChatCost(1024, undefined, "deepseek/deepseek-chat", undefined, 100_000), ); }); + +// GLM goes through Alpha.sh, and zai/glm-5.3 is the only SKU the gateway maps +// there (blockrun ALPHA_MODEL_MAP). mode:"glm" used to start at glm-5 and never +// listed 5.3, so it could not reach Alpha at all. +test('mode:"glm" and mode:"coding" use zai/glm-5.3, the Alpha-served GLM', () => { + assert.equal(MODEL_TIERS.glm[0], "zai/glm-5.3"); + assert.ok((MODEL_TIERS.coding as readonly string[]).includes("zai/glm-5.3")); + assert.ok(!(MODEL_TIERS.coding as readonly string[]).includes("zai/glm-5.2")); +});