pi-makora-provider 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  **Open-weight models through [Makora](https://inference.makora.com)**
6
6
 
7
- _DeepSeek V4, Kimi K2.7 Code, GLM 5.2, Qwen 3.6 — with client-side tool call repair and preserved-thinking flags for [pi](https://github.com/earendil-works/pi-coding-agent)._
7
+ _DeepSeek V4, Kimi K2.7 Code, GLM 5.2, Qwen 3.6 for [pi](https://github.com/earendil-works/pi-coding-agent)._
8
8
 
9
9
  [![pi extension](https://img.shields.io/badge/pi-extension-blueviolet)](https://github.com/earendil-works/pi-coding-agent)
10
10
  [![license](https://img.shields.io/badge/license-MIT-blue)](./LICENSE)
@@ -18,15 +18,15 @@ _DeepSeek V4, Kimi K2.7 Code, GLM 5.2, Qwen 3.6 — with client-side tool call r
18
18
  <!-- MODELS_TABLE_START -->
19
19
  | Model | ID | Reasoning | Notes |
20
20
  |-------|----|-----------|-------|
21
- | DeepSeek V4 Flash | `deepseek-ai/DeepSeek-V4-Flash` | Yes | `include_reasoning` + `chat_template_kwargs.thinking` via `before_provider_request` payload rewrite; returns `reasoning` field |
22
- | DeepSeek V4 Pro | `deepseek-ai/DeepSeek-V4-Pro` | Yes | `chat_template_kwargs.thinking` via `before_provider_request` payload rewrite; returns `reasoning` field |
21
+ | DeepSeek V4 Flash | `deepseek-ai/DeepSeek-V4-Flash` | Yes | returns `reasoning` field |
22
+ | DeepSeek V4 Pro | `deepseek-ai/DeepSeek-V4-Pro` | Yes | returns `reasoning` field |
23
23
  | GLM 5.2 FP8 | `zai-org/GLM-5.2-FP8` | Yes | `enable_thinking` via `qwen-chat-template`; effort via `reasoning_effort` (only `high`/`max` distinct, per vLLM GLM-5.2 recipe); thinking levels aligned with neuralwatt GLM 5.2; returns `reasoning` field |
24
24
  | GLM 5.2 NVFP4 | `zai-org/GLM-5.2-NVFP4` | Yes | `enable_thinking` via `qwen-chat-template`; effort via `reasoning_effort` (only `high`/`max` distinct, per vLLM GLM-5.2 recipe); returns `reasoning` field |
25
- | Kimi K2.7 Code | `moonshotai/Kimi-K2.7-Code` | Yes | Reasoning on by default (thinking-only model); `preserve_thinking` via `chatTemplateKwargs` for multi-turn continuity; returns `reasoning` field; client-side tool call parsing (vLLM streaming parser bypass) |
25
+ | Kimi K2.7 Code | `moonshotai/Kimi-K2.7-Code` | Yes | Reasoning on by default (thinking-only model); `preserve_thinking` via `chatTemplateKwargs` for multi-turn continuity; returns `reasoning` field |
26
26
  | Llama 3.3 70B FP8 | `amd/Llama-3.3-70B-Instruct-FP8-KV` | No | |
27
27
  | Llama 3.3 70B Instruct | `meta-llama/Llama-3.3-70B-Instruct` | No | |
28
- | Qwen 3.6 27B NVFP4 | `unsloth/Qwen3.6-27B-NVFP4` | Yes | `enable_thinking` via `qwen-chat-template`; `preserve_thinking` via `chatTemplateKwargs` for multi-turn continuity; returns `reasoning` field; client-side tool call parsing (vLLM streaming parser bypass) |
29
- | Qwen 3.6 35B A3B NVFP4 | `unsloth/Qwen3.6-35B-A3B-NVFP4` | Yes | `enable_thinking` via `qwen-chat-template`; `preserve_thinking` via `chatTemplateKwargs` for multi-turn continuity; returns `reasoning` field; client-side tool call parsing (vLLM streaming parser bypass) |
28
+ | Qwen 3.6 27B NVFP4 | `unsloth/Qwen3.6-27B-NVFP4` | Yes | `enable_thinking` via `qwen-chat-template`; `preserve_thinking` via `chatTemplateKwargs` for multi-turn continuity; returns `reasoning` field |
29
+ | Qwen 3.6 35B A3B NVFP4 | `unsloth/Qwen3.6-35B-A3B-NVFP4` | Yes | `enable_thinking` via `qwen-chat-template`; `preserve_thinking` via `chatTemplateKwargs` for multi-turn continuity; returns `reasoning` field |
30
30
  <!-- MODELS_TABLE_END -->
31
31
 
32
32
  ## Installation
@@ -156,24 +156,3 @@ Do **not** edit `models.json` directly — it is auto-generated from the API. To
156
156
  - The API is OpenAI-compatible (chat completions format)
157
157
  - All models are hosted on vLLM
158
158
  - The `developer` role is not supported (prompts are silently dropped); `supportsDeveloperRole` is set to `false` for all models
159
-
160
- ## vLLM Caveats
161
-
162
- These issues are common to all vLLM-hosted providers and affect Makora models:
163
-
164
- - **GLM tool calls — follow-up `tool_calls` crash workaround**: the ZAI chat template calls `.items()` on any assistant message that carries a `tool_calls` field (on the `tool_calls` list or on its JSON-string `arguments` field), raising a leaked Python `AttributeError` that vLLM returns as HTTP 400 (`'list object' has no attribute 'items'` / `'str object' has no attribute 'items'`). The `before_provider_request` hook (`stripGlmToolCalls`) strips `tool_calls` from assistant messages and converts them to GLM-native `<tool_call>` XML text in `content` — which the model natively understands in conversation history — before the follow-up request is sent. The hook is scoped to Makora's own GLM models via an exact model-id match (`isMakoraGlmVllmModel`): `before_provider_request` is global in pi (it fires for every loaded provider's requests and the event carries no `provider` field), so gating by model id is what keeps it from touching GLM models served by other providers. If upstream fixes the `.items()` crash, this transform is a harmless no-op (the XML text is valid GLM input either way).
165
-
166
- - **Kimi K2.7 Code + Qwen 3.6 tool calling**: vLLM's server-side streaming tool-call handling is broken or missing for these models — Makora's vLLM is missing both `--enable-auto-tool-choice` and `--tool-call-parser` for them, so they emit tool calls as raw text tokens rather than structured `tool_call` deltas.
167
-
168
- - **Kimi K2.7 Code**: Uses `<|tool_call_begin|>...<|tool_call_end|>` tokens.
169
- - **Qwen 3.6**: Uses hermes-style `<function=...>` XML, sometimes with `█` delimiters.
170
-
171
- - **GLM 5.2 CoT leak**: On some vLLM builds, disabling reasoning may still leak chain-of-thought into `content` terminated by a ``` marker. See [vllm-project/vllm#31319](https://github.com/vllm-project/vllm/issues/31319).
172
-
173
- - **DeepSeek V4 reasoning**: The official DeepSeek API uses `thinking: { type: "enabled" }` which Makora's vLLM silently ignores. The `before_provider_request` hook rewrites the payload to use vLLM-native params instead:
174
- - **DS V4 Pro**: `chat_template_kwargs: { thinking: true }`. Returns `reasoning` (vLLM reasoning parser; the official DeepSeek API returns `reasoning_content`, but Makora's vLLM build returns `reasoning`).
175
- - **DS V4 Flash**: `include_reasoning: true` + `chat_template_kwargs: { thinking: true }`. `include_reasoning` alone returns `reasoning: null` on this vLLM build — both params are required. Returns `reasoning`.
176
- - **Preserved thinking (multi-turn reasoning continuity)**: every reasoning model on Makora returns reasoning in the `reasoning` field (not `reasoning_content`). Pi sends prior assistant reasoning back on follow-up turns; Makora's vLLM chat templates accept it under either `reasoning` or `reasoning_content`. For models whose chat template defines an explicit preserved-thinking flag, the flag is sent via `compat.chatTemplateKwargs`:
177
- - **Kimi K2.7 Code**: `preserve_thinking: true` (the model forces thinking-only mode with preserve_thinking on, per the vLLM recipe).
178
- - **Qwen 3.6 27B / 35B**: `preserve_thinking: true` (Qwen 3.6 ships with preserve_thinking).
179
- - **GLM 5.2**: no extra flag — the vLLM GLM-5.2 recipe uses only `enable_thinking` + `reasoning_effort`; preserved thinking works without a dedicated flag. Effort honors only `high` and `max` (lower pi levels resolve to the default `max`).
package/index.ts CHANGED
@@ -13,30 +13,11 @@
13
13
  * Model resolution strategy: static models.json merged with custom-models.json
14
14
  *
15
15
  * Reasoning notes:
16
- * - DeepSeek V4 Pro: reasoning via chat_template_kwargs.thinking on vLLM.
17
- * pi sends thinking: { type } via the "deepseek" thinkingFormat, but vLLM
18
- * ignores that — the before_provider_request hook rewrites the payload to
19
- * use chat_template_kwargs: { thinking: true } instead.
20
- * Returns reasoning field (vLLM reasoning parser; not reasoning_content).
21
- * - DeepSeek V4 Flash: reasoning via include_reasoning +
22
- * chat_template_kwargs.thinking on vLLM.
23
- * The before_provider_request hook rewrites the payload to replace
24
- * thinking: { type } with include_reasoning: true +
25
- * chat_template_kwargs: { thinking: true }.
26
- * include_reasoning alone returns reasoning: null on this vLLM build.
27
- * Returns reasoning field.
28
- * - GLM 5.2 FP8 / NVFP4: reasoning via chat_template_kwargs.enable_thinking.
29
- * Effort uses vLLM's reasoning_effort field (only `high` and `max` are
30
- * distinct levels per the vLLM GLM-5.2 recipe; lower pi levels resolve to
31
- * the default). Thinking levels aligned with the neuralwatt provider's
32
- * GLM 5.2 configuration and mapped through pi's qwen-chat-template
33
- * thinkingFormat. Returns `reasoning` field.
34
- * - Kimi K2.7 Code: reasoning always on (thinking-only model);
35
- * chatTemplateKwargs.preserve_thinking forces multi-turn reasoning
36
- * continuity. Returns `reasoning` field. Can be toggled via enable_thinking.
37
- * - Qwen 3.6 models: reasoning via chat_template_kwargs.enable_thinking;
38
- * chatTemplateKwargs.preserve_thinking for multi-turn continuity.
39
- * Returns `reasoning` field.
16
+ * - DeepSeek V4 Pro: returns `reasoning` field.
17
+ * - DeepSeek V4 Flash: returns `reasoning` field.
18
+ * - GLM 5.2 FP8 / NVFP4: returns `reasoning` field.
19
+ * - Kimi K2.7 Code: returns `reasoning` field.
20
+ * - Qwen 3.6 models: returns `reasoning` field.
40
21
  * - Llama 3.3 70B: not a reasoning model.
41
22
  *
42
23
  * Developer role is NOT supported by any of the chat templates on Makora's
@@ -129,11 +110,6 @@ interface PatchEntry {
129
110
 
130
111
  type PatchMap = Record<string, PatchEntry>;
131
112
 
132
- /** Type guard: non-null, non-array object. */
133
- export function isObject(value: unknown): value is Record<string, unknown> {
134
- return value !== null && typeof value === "object" && !Array.isArray(value);
135
- }
136
-
137
113
  // Patch Application
138
114
 
139
115
  function applyPatch(model: JsonModel, patch: PatchEntry): JsonModel {
@@ -212,157 +188,11 @@ function buildModels(
212
188
  const PROVIDER_ID = "makora";
213
189
  const BASE_URL = "https://inference.makora.com/v1";
214
190
 
215
- const DS_PRO_ID = "deepseek-ai/DeepSeek-V4-Pro";
216
- const DS_FLASH_ID = "deepseek-ai/DeepSeek-V4-Flash";
217
-
218
- const DS_VLLM_MODELS = new Set([DS_PRO_ID, DS_FLASH_ID]);
219
-
220
- /**
221
- * Makora's GLM models, built from the same models list this extension
222
- * registers. `before_provider_request` is GLOBAL in pi — it fires for every
223
- * loaded provider's requests, not just makora's — and its event carries only
224
- * `payload` (no `provider` field to gate on). So the GLM tool_calls strip MUST
225
- * be scoped to makora's own GLM model ids. A loose `/glm/i` regex would also
226
- * rewrite tool_calls for every sibling provider that serves any GLM model
227
- * (baseten, io, lilac, neuralwatt, tensorix, fireworks, crofai, hypercharm,
228
- * wafer, parasail, umans, opencode, ...), silently breaking their tool calling
229
- * and clobbering the input their own before_provider_request handlers expect.
230
- *
231
- * Derived (not hardcoded) so it auto-tracks models.json refreshes — models.json
232
- * is auto-generated by scripts/update-models.js. All makora models run on vLLM,
233
- * so every GLM id here shares the ZAI chat-template `.items()` crash that
234
- * stripGlmToolCalls works around.
235
- */
236
191
  const allMakoraModels = buildModels(
237
192
  modelsData as JsonModel[],
238
193
  customModelsData as JsonModel[],
239
194
  patchData as PatchMap,
240
195
  );
241
- const GLM_VLLM_MODELS = new Set(
242
- allMakoraModels.filter((m) => /glm/i.test(m.id)).map((m) => m.id),
243
- );
244
-
245
- /** Whether `model` is one of makora's GLM models — the only ids the
246
- * before_provider_request hook should strip tool_calls for. Exported so the
247
- * scoping can be unit-tested in isolation. */
248
- export function isMakoraGlmVllmModel(model: string): boolean {
249
- return GLM_VLLM_MODELS.has(model);
250
- }
251
-
252
- /**
253
- * Intercept the request payload for models that need vLLM-specific thinking
254
- * param rewrites.
255
- *
256
- * pi's "deepseek" thinkingFormat sends `thinking: { type: "enabled" }` which
257
- * is the official DeepSeek API format — but Makora's vLLM deployment ignores
258
- * it. vLLM requires different params depending on the model:
259
- * - DS V4 Pro: `chat_template_kwargs: { thinking: true }` + `reasoning_effort`
260
- * - DS V4 Flash: `include_reasoning: true` + `chat_template_kwargs: { thinking: true }`
261
- * + `reasoning_effort`. `include_reasoning` alone returns `reasoning: null`
262
- * on this vLLM build — both params are required.
263
- *
264
- * This hook rewrites the payload accordingly.
265
- */
266
- function rewriteVllmPayload(payload: Record<string, unknown>): Record<string, unknown> {
267
- const model = payload.model as string | undefined;
268
- if (!model) return payload;
269
-
270
- const p = { ...payload };
271
-
272
- if (DS_VLLM_MODELS.has(model)) {
273
- // Remove the DeepSeek API-style `thinking` param that vLLM ignores
274
- delete p.thinking;
275
-
276
- if (model === DS_PRO_ID) {
277
- // DS Pro: chat_template_kwargs.thinking + reasoning_effort
278
- const ctq = (p.chat_template_kwargs as Record<string, unknown>) ?? {};
279
- p.chat_template_kwargs = { ...ctq, thinking: true };
280
- } else if (model === DS_FLASH_ID) {
281
- // DS Flash: include_reasoning + chat_template_kwargs.thinking + reasoning_effort
282
- // vLLM requires *both* include_reasoning and chat_template_kwargs.thinking:
283
- // include_reasoning alone returns reasoning: null.
284
- p.include_reasoning = true;
285
- const ctq = (p.chat_template_kwargs as Record<string, unknown>) ?? {};
286
- p.chat_template_kwargs = { ...ctq, thinking: true };
287
- }
288
- }
289
-
290
- return p;
291
- }
292
-
293
- /**
294
- * GLM models on Makora's vLLM crash with a leaked Python AttributeError
295
- * (`'list object' has no attribute 'items'` or `'str object' has no attribute 'items'`)
296
- * when any assistant message in the request contains a `tool_calls` field.
297
- * The ZAI/vLLM chat template calls `.items()` on the tool_calls list (or on the
298
- * JSON-string `arguments` field), which raises AttributeError and leaks into the
299
- * HTTP 400 response body.
300
- *
301
- * Fix: for makora's GLM models only (see GLM_VLLM_MODELS / isMakoraGlmVllmModel),
302
- * strip `tool_calls` from assistant messages in the before_provider_request hook
303
- * and convert them back to GLM's native
304
- * `<tool_call>` XML text in `content`. The model natively understands this
305
- * format in conversation history, and the `role: "tool"` result messages that
306
- * follow are rendered fine by the chat template's tool-observation branch.
307
- *
308
- * If upstream fixes both the streaming parser and the 500/400 crash, this
309
- * transform becomes a harmless no-op (the XML text is still valid GLM input).
310
- */
311
-
312
- export function toolCallToGlmXml(tc: Record<string, unknown>): string {
313
- const fn = (isObject(tc.function) ? tc.function : {}) as Record<string, unknown>;
314
- const name = typeof fn.name === "string" ? fn.name : "";
315
- const argsStr = typeof fn.arguments === "string" ? fn.arguments : "{}";
316
- let args: Record<string, unknown>;
317
- try {
318
- args = JSON.parse(argsStr) as Record<string, unknown>;
319
- } catch {
320
- args = {};
321
- }
322
- if (!isObject(args)) args = {};
323
- const argLines = Object.entries(args).map(
324
- ([key, value]) =>
325
- `<arg_key>${key}</arg_key>\n<arg_value>${
326
- typeof value === "string" ? value : JSON.stringify(value)
327
- }</arg_value>`,
328
- );
329
- return `<tool_call>${name}\n${argLines.join("\n")}\n</tool_call>`;
330
- }
331
-
332
- export function stripGlmToolCalls(payload: Record<string, unknown>): Record<string, unknown> {
333
- const messages = payload.messages;
334
- if (!Array.isArray(messages)) return payload;
335
-
336
- let modified = false;
337
- const newMessages = messages.map((msg) => {
338
- if (!isObject(msg)) return msg;
339
- if (msg.role !== "assistant") return msg;
340
-
341
- const toolCalls = msg.tool_calls;
342
- if (!Array.isArray(toolCalls) || toolCalls.length === 0) return msg;
343
-
344
- const xmlBlocks = toolCalls
345
- .filter((tc): tc is Record<string, unknown> => isObject(tc))
346
- .map(toolCallToGlmXml);
347
- if (xmlBlocks.length === 0) return msg;
348
-
349
- const toolCallText = xmlBlocks.join("\n");
350
- // pi's openai-completions provider always serializes assistant content as a
351
- // plain string, but guard against null/array content for robustness.
352
- const existingContent = typeof msg.content === "string" ? msg.content : "";
353
- const newContent = existingContent ? `${existingContent}\n${toolCallText}` : toolCallText;
354
-
355
- modified = true;
356
- const rest: Record<string, unknown> = {};
357
- for (const [k, v] of Object.entries(msg)) {
358
- if (k !== "tool_calls") rest[k] = v;
359
- }
360
- return { ...rest, content: newContent };
361
- });
362
-
363
- if (!modified) return payload;
364
- return { ...payload, messages: newMessages };
365
- }
366
196
 
367
197
  export default function (pi: ExtensionAPI) {
368
198
  const models = allMakoraModels;
@@ -375,16 +205,4 @@ export default function (pi: ExtensionAPI) {
375
205
  api: "openai-completions",
376
206
  models,
377
207
  });
378
-
379
- pi.on("before_provider_request", (event) => {
380
- const payload = event.payload as Record<string, unknown> | undefined;
381
- if (!payload || typeof payload.model !== "string") return;
382
-
383
- let result = rewriteVllmPayload(payload);
384
- if (isMakoraGlmVllmModel(payload.model)) {
385
- result = stripGlmToolCalls(result);
386
- }
387
- return result;
388
- });
389
208
  }
390
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-makora-provider",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "Makora provider extension for pi - Access DeepSeek V4, GLM 5.2, Kimi K2.7 Code, Llama 3.3, Qwen 3.6, and more through the Makora inference API",
5
5
  "type": "module",
6
6
  "main": "index.ts",
package/patch.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "deepseek-ai/DeepSeek-V4-Flash": {
3
3
  "reasoning": true,
4
- "notes": "`include_reasoning` + `chat_template_kwargs.thinking` via `before_provider_request` payload rewrite; returns `reasoning` field",
4
+ "notes": "returns `reasoning` field",
5
5
  "thinkingLevelMap": {
6
6
  "minimal": null,
7
7
  "low": null,
@@ -16,7 +16,7 @@
16
16
  },
17
17
  "deepseek-ai/DeepSeek-V4-Pro": {
18
18
  "reasoning": true,
19
- "notes": "`chat_template_kwargs.thinking` via `before_provider_request` payload rewrite; returns `reasoning` field",
19
+ "notes": "returns `reasoning` field",
20
20
  "thinkingLevelMap": {
21
21
  "minimal": null,
22
22
  "low": null,
@@ -32,7 +32,7 @@
32
32
  },
33
33
  "unsloth/Qwen3.6-27B-NVFP4": {
34
34
  "reasoning": true,
35
- "notes": "`enable_thinking` via `qwen-chat-template`; `preserve_thinking` via `chatTemplateKwargs` for multi-turn continuity; returns `reasoning` field; client-side tool call parsing (vLLM streaming parser bypass)",
35
+ "notes": "`enable_thinking` via `qwen-chat-template`; `preserve_thinking` via `chatTemplateKwargs` for multi-turn continuity; returns `reasoning` field",
36
36
  "thinkingLevelMap": {
37
37
  "minimal": "low",
38
38
  "xhigh": "high"
@@ -47,7 +47,7 @@
47
47
  },
48
48
  "unsloth/Qwen3.6-35B-A3B-NVFP4": {
49
49
  "reasoning": true,
50
- "notes": "`enable_thinking` via `qwen-chat-template`; `preserve_thinking` via `chatTemplateKwargs` for multi-turn continuity; returns `reasoning` field; client-side tool call parsing (vLLM streaming parser bypass)",
50
+ "notes": "`enable_thinking` via `qwen-chat-template`; `preserve_thinking` via `chatTemplateKwargs` for multi-turn continuity; returns `reasoning` field",
51
51
  "thinkingLevelMap": {
52
52
  "minimal": "low",
53
53
  "xhigh": "high"
@@ -66,7 +66,7 @@
66
66
  "text",
67
67
  "image"
68
68
  ],
69
- "notes": "Reasoning on by default (thinking-only model); `preserve_thinking` via `chatTemplateKwargs` for multi-turn continuity; returns `reasoning` field; client-side tool call parsing (vLLM streaming parser bypass)",
69
+ "notes": "Reasoning on by default (thinking-only model); `preserve_thinking` via `chatTemplateKwargs` for multi-turn continuity; returns `reasoning` field",
70
70
  "thinkingLevelMap": {
71
71
  "minimal": "low",
72
72
  "xhigh": "high"