import type { ExtensionAPI } from "@earendil-works/pi-coding-agent"; /** * New API gateway (https://github.com/Calcium-Ion/new-api) aggregation provider. * * Routes a self-hosted New API instance — which normalizes many upstream * vendors (Zhipu GLM, Kimi/Moonshot, Anthropic, OpenAI, …) behind a single * OpenAI-compatible `/v1/chat/completions` endpoint — as one Pi provider. * * Configure with: * NEW_API_KEY=sk-... # token issued by the New API dashboard * NEW_API_BASE_URL=http://… # optional override (defaults to the address below) * * Model `compat` blocks mirror the built-in pi-ai provider definitions so the * gateway behaves identically to talking to each vendor directly: * - GLM 5.2 / 4.7 ← zai-coding-cn (thinkingFormat "zai", zaiToolStream) * - K3 / K3-256K ← moonshotai kimi-k3 (thinkingFormat "openai", deferred * tools, reasoning_effort, reasoning_content replay) * - kimi-for-coding← moonshotai kimi-k2.7-code (thinkingFormat "deepseek") */ export default function (pi: ExtensionAPI) { // Gateway address. Resolved once, when the extension loads, from the // environment so it can be overridden without touching code. `apiKey` below // still uses pi's `$ENV` config-value syntax so pi can cache/refresh it. const baseUrl = process.env.NEW_API_BASE_URL || "http://10.30.60.169:3000/v1"; pi.registerProvider("new-api", { name: "New API Gateway", baseUrl, apiKey: "$NEW_API_KEY", authHeader: true, // New API tokens are sent as `Authorization: Bearer ` api: "openai-completions", models: [ // ── 智谱 GLM 5.2 ────────────────────────────────────── // Mirrors pi-ai `zai-coding-cn` glm-5.2 definition. { id: "glm-5.2", name: "GLM 5.2", reasoning: true, thinkingLevelMap: { minimal: null, low: "high", medium: "high", high: "high", max: "max", }, input: ["text"], cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 }, contextWindow: 1000000, maxTokens: 131072, compat: { supportsStore: false, supportsDeveloperRole: false, supportsReasoningEffort: true, }, }, // ── 智谱 GLM 4.7 ────────────────────────────────────── // Mirrors pi-ai `zai-coding-cn` glm-4.7 definition. { id: "glm-4.7", name: "GLM 4.7", reasoning: true, input: ["text"], cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 }, contextWindow: 204800, maxTokens: 131072, compat: { supportsStore: false, supportsDeveloperRole: false, supportsReasoningEffort: false, }, }, // ── Kimi K3 ─────────────────────────────────────────── // Mirrors pi-ai `moonshotai` / `moonshotai-cn` kimi-k3 definition, // exposed through the gateway under the official id `k3`. { id: "k3", name: "Kimi K3", reasoning: true, input: ["text", "image"], cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 }, contextWindow: 1048576, maxTokens: 131072, thinkingLevelMap: { off: null, minimal: null, low: "low", medium: null, high: "high", xhigh: null, max: "max", }, compat: { supportsStore: false, supportsDeveloperRole: false, supportsReasoningEffort: true, maxTokensField: "max_tokens", supportsStrictMode: false, thinkingFormat: "openai", requiresReasoningContentOnAssistantMessages: true, deferredToolsMode: "kimi", }, }, // ── Kimi K3 (256K context) ──────────────────────────── // Same upstream model as `k3`; the gateway offers a shorter context // variant. Only the context window differs. { id: "k3-256k", name: "Kimi K3 256K", reasoning: true, input: ["text", "image"], cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 }, contextWindow: 262144, maxTokens: 131072, thinkingLevelMap: { off: null, minimal: null, low: "low", medium: null, high: "high", xhigh: null, max: "max", }, compat: { supportsStore: false, supportsDeveloperRole: false, supportsReasoningEffort: true, maxTokensField: "max_tokens", supportsStrictMode: false, thinkingFormat: "openai", requiresReasoningContentOnAssistantMessages: true, deferredToolsMode: "kimi", }, }, // ── Kimi for Coding (K2.7 Code) ─────────────────────── // Mirrors pi-ai `moonshotai` / `moonshotai-cn` kimi-k2.7-code definition, // exposed through the gateway under the official id `kimi-for-coding`. { id: "kimi-for-coding", name: "Kimi For Coding", reasoning: true, input: ["text", "image"], cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 }, contextWindow: 262144, maxTokens: 262144, thinkingLevelMap: { off: null, }, compat: { supportsStore: false, supportsDeveloperRole: false, supportsReasoningEffort: false, maxTokensField: "max_tokens", supportsStrictMode: false, thinkingFormat: "deepseek", }, }, ], }); }