pi-tsgw 0.0.12 → 0.0.15

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
@@ -37,10 +37,11 @@ Example:
37
37
  {
38
38
  "tsgw": {
39
39
  "baseUrl": "https://aih.example.net",
40
+ "mcpUrl": "https://xn--oht.cc/mcp",
40
41
  "tsSearch": "live",
41
42
  "traceHeaders": false,
42
43
  "excludeModels": ["gpt-*", "claude-*"],
43
- "includeModels": ["gpt-5.6-*"]
44
+ "includeModels": ["gpt-6-*"]
44
45
  }
45
46
  }
46
47
  ```
@@ -69,6 +70,7 @@ catalog may fall back to static models until Pi refreshes it.
69
70
  | Setting (`settings.json` `tsgw.*`) | Default | Meaning |
70
71
  | --- | --- | --- |
71
72
  | `baseUrl` | placeholder | Gateway root (the `/v1` suffix is normalized away) |
73
+ | `mcpUrl` | `https://xn--oht.cc/mcp` | Optional `ts_oht` HTTP(S) endpoint override; independent of the model gateway |
72
74
  | `tsSearch` | `live` | GPT: `cached` or `live`; unset, legacy `off`, and invalid values fall back to `live`. Supported Grok models always use live search. |
73
75
  | `traceHeaders` | `false` | Adds `AH-Thread-Id` / `AH-Trace-Id` headers for gateway-side tracing |
74
76
  | `includeModels` | unset | Re-include override: matching model ids are kept even when also matched by `excludeModels` (exact id or `prefix-*` glob) |
@@ -79,11 +81,41 @@ catalog may fall back to static models until Pi refreshes it.
79
81
  The catalog is assembled from per-vendor slices (`extensions/models/vendors/`),
80
82
  covering 11 vendor families: DeepSeek, GLM (Zhipu), MiMo (Xiaomi), MiniMax,
81
83
  Kimi (Moonshot), Qwen (Alibaba), GPT (OpenAI), Gemini (Google), Claude
82
- (Anthropic), LongCat, and Grok (xAI). The current static catalog contains 54 chat
84
+ (Anthropic), LongCat, and Grok (xAI). The current static catalog contains 36 chat
83
85
  model IDs, including retained aliases; this is not a live availability count.
84
86
  Vendor files carry documentation links and metadata caveats. Alias mappings,
85
87
  output limits, and shared thinking policies are not all individually verified
86
88
  against gateway endpoints; public-price estimates do not guarantee billing.
89
+ MiMo uses `mimo-v2.6-pro` and `mimo-v2.6-flash`; the former V2.5 IDs are not
90
+ registered. Update any explicit model selections or filter rules to the new IDs.
91
+
92
+ The curated catalog keeps DeepSeek `deepseek-flash` and V4 Pro; GLM 5.2+,
93
+ plus the explicit `glm-4.5-air` exception; MiniMax M3+; Kimi K3; GPT 6+;
94
+ and Gemini 3.5+ plus the unversioned `gemini-flash` / `gemini-pro` aliases.
95
+ Qwen, MiMo, LongCat, Claude, and Grok retain their existing registrations.
96
+ Removed IDs and their dedicated request policies are no longer registered;
97
+ include rules cannot restore them, even if a gateway still lists them. Existing
98
+ explicit model selections referencing removed IDs need to be updated.
99
+
100
+ Kimi offers `kimi-k3` and the gateway variant `kimi-k3-256k`, displayed as
101
+ **Kimi K3 (256K)** with a 262,144-token context window. Its other metadata,
102
+ price estimates, and thinking policy are inherited from K3; the 131,072-token
103
+ output setting is separate from context size. These inherited values are not
104
+ individual endpoint verification or a guarantee of the variant's billing rates.
105
+
106
+ The catalog also includes `MiniMax-M3.1-Flash-Preview`, `glm-5.3`,
107
+ `glm-5.3-flash`, and `glm-5.3-flashx`. All four require thinking: MiniMax
108
+ uses low/medium/high/xhigh/max; GLM uses low/high/max. Unsupported `off` is
109
+ disabled in model metadata, and stale off/minimal requests map to low rather
110
+ than silently selecting the default max. MiniMax and GLM Flash/FlashX support
111
+ image input; GLM 5.3 is text-only. Registration does not prove gateway
112
+ inference or tool-call support.
113
+
114
+ As checked on 2026-10-16, MiniMax publishes subscription access but no per-token
115
+ price for M3.1 Flash Preview. Its zero cost fields mean **unknown**, not free,
116
+ and usage cost totals therefore omit its actual charges. GLM 5.3 price estimates
117
+ use domestic public rates and the existing fixed USD/CNY conversion; temporary
118
+ free cache storage is recorded as zero, not a permanent billing guarantee.
87
119
 
88
120
  Use broad `excludeModels` rules to drop model families and precise
89
121
  `includeModels` rules to pull selected models back. `includeModels` is not a
@@ -149,6 +181,61 @@ buttons. Busy sessions disable the buttons. The terminal CLI shows the same
149
181
  statuses as text; use the slash commands there. Pi Web may not show extension
150
182
  statuses until the session runtime has started.
151
183
 
184
+ ## Subagent orchestration skill
185
+
186
+ The package ships [delegate-model-selection](skills/delegate-model-selection/SKILL.md),
187
+ which encourages suitable tasks to run through background subagents and provides
188
+ model/thinking-level guidance, including independent Kimi + Astra reviews.
189
+ Task splitting, parallelism, validation, and escalation remain the agent's choice.
190
+
191
+ The plugin maintains the reference table in the same `SKILL.md`
192
+ for direct use, without asking agents to check live rankings or data freshness.
193
+ It is guidance, not a model whitelist or fixed execution sequence. Prices are
194
+ API reference rates, not subscription charges. GLM guidance uses 5.3, with Flash
195
+ and FlashX as alternatives. Thinking levels use Pi names: M3 recommends `high`,
196
+ which maps to adaptive like its other non-off levels.
197
+
198
+ Pi discovers the skill through the package manifest after installation and
199
+ `/reload`, unless skills are disabled or filtered by the host/package settings.
200
+ Loading only `extensions/index.ts` does not load package skills. A host-provided
201
+ subagent tool with model selection and available `tsgw` models is required; this
202
+ package does not supply that tool or change dispatch settings, user rules, or
203
+ permissions.
204
+
205
+ ## Default MCP registration
206
+
207
+ The plugin registers `ts_oht` at `https://xn--oht.cc/mcp` with `codemode`
208
+ exposure on each load. No MCP configuration is required to use this default.
209
+ An optional `tsgw.mcpUrl` in the user-level settings changes the plugin's endpoint;
210
+ it is independent of `tsgw.baseUrl` and is read once at initialization. Invalid
211
+ explicit URLs skip this registration with a safe warning, rather than silently
212
+ connecting to the default. Older hosts without `registerMcpServer` skip it.
213
+
214
+ Pi manages connections, OAuth sign-in and credentials. Use `/mcp login ts_oht`
215
+ inside a session if sign-in is required. The plugin does not read or write
216
+ `mcp.json` or `mcp-auth.json`, and does not carry credentials. Keep the same
217
+ server name and exact URL to reuse the host's existing OAuth scope.
218
+
219
+ A same-name `ts_oht` in the effective global/project `mcp.json` takes precedence
220
+ over the plugin registration, including `enabled: false`; the plugin does not
221
+ create a second connection or bypass that choice. Use a complete same-name
222
+ file configuration to override the URL, exposure, timeout, auth, or enabled state.
223
+ Changes to a plugin-provided server apply only to the current session; they are
224
+ not saved. Shell `pi mcp` commands do not load plugins and cannot see servers
225
+ provided only by this registration. Reload or restart after configuration changes.
226
+
227
+ ## Local file upload
228
+
229
+ The `upload_local_file` tool uploads an authorized file from the Pi host directly
230
+ to S3 using the already-connected `ts_oht` MCP for signing. It supports single
231
+ PUTs and streaming multipart uploads, explicit recovery, custom download expiry
232
+ and inline/attachment links. It uses the host-managed connection and stores no credentials.
233
+
234
+ Upload support requires a host with `ctx.executeTool` (tested with Pi 1.1.0) and
235
+ callable `ts_oht` upload tools. File access uses host OS permissions, not a
236
+ sandbox. See [upload usage and safety boundaries](extensions/upload/README.md)
237
+ before enabling it in an environment with sensitive files.
238
+
152
239
  ## Development
153
240
 
154
241
  ```bash
@@ -28,6 +28,8 @@ import {
28
28
  type CatalogStatus,
29
29
  } from "./status.ts";
30
30
  import type { ThinkingLevel, WebSearchMode } from "./models/_tools.ts";
31
+ import { registerUploadTool } from "./upload/index.ts";
32
+ import { registerTsgwMcp } from "./mcp.ts";
31
33
 
32
34
  /**
33
35
  * The data needed by provider hooks, copied while the lifecycle context is
@@ -55,6 +57,7 @@ interface RequestModel {
55
57
  */
56
58
  interface TsgwSettings {
57
59
  baseUrl?: string;
60
+ mcpUrl?: string;
58
61
  tsSearch?: string;
59
62
  traceHeaders?: boolean;
60
63
  includeModels?: string[];
@@ -195,7 +198,9 @@ async function resolveEffectiveModels(
195
198
  }
196
199
 
197
200
  export default async function registerTsgw(pi: ExtensionAPI): Promise<void> {
201
+ registerUploadTool(pi);
198
202
  const settings = readTsgwSettings();
203
+ registerTsgwMcp(pi, settings.mcpUrl);
199
204
  const root = rootForRuntime(settings.baseUrl);
200
205
  const defaultSearchMode: WebSearchMode =
201
206
  settings.tsSearch === "cached" || settings.tsSearch === "live"
@@ -0,0 +1,26 @@
1
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
+
3
+ export const TS_OHT_NAME = "ts_oht";
4
+ export const TS_OHT_URL = "https://xn--oht.cc/mcp";
5
+
6
+ /** Session default only; Pi owns file overrides, connections and OAuth. */
7
+ export function registerTsgwMcp(pi: ExtensionAPI, configuredUrl?: unknown): void {
8
+ const value = configuredUrl === undefined ? TS_OHT_URL : configuredUrl;
9
+ try {
10
+ if (typeof value !== "string" || value.trim() !== value) throw new Error();
11
+ const url = new URL(value);
12
+ if (!["https:", "http:"].includes(url.protocol) || url.username || url.password || url.hash)
13
+ throw new Error();
14
+ } catch {
15
+ // Invalid explicit configuration must not connect to a different default.
16
+ // Never include URLs or parser errors in ordinary logs.
17
+ console.error("TSGW: invalid mcpUrl; ts_oht registration skipped.");
18
+ return;
19
+ }
20
+ if (typeof pi.registerMcpServer !== "function") {
21
+ console.error("TSGW: this Pi host cannot register MCP servers; ts_oht registration skipped.");
22
+ return;
23
+ }
24
+ // Preserve the exact URL because Pi binds OAuth to server name + URL.
25
+ pi.registerMcpServer(TS_OHT_NAME, { url: value as string, exposure: "codemode" });
26
+ }
@@ -47,7 +47,7 @@ export interface ModelFilter {
47
47
  exclude?: readonly string[];
48
48
  }
49
49
 
50
- /** 前缀通配匹配:`gpt-5.6-*` 命中该系列全部;不带 `*` 时精确匹配。 */
50
+ /** 前缀通配匹配:`gpt-6-*` 命中该系列全部;不带 `*` 时精确匹配。 */
51
51
  function matches(pattern: string, id: string): boolean {
52
52
  if (pattern.endsWith("*")) return id.startsWith(pattern.slice(0, -1));
53
53
  return pattern === id;
@@ -8,8 +8,13 @@ const DEEPSEEK_RESPONSES_COMPAT = {
8
8
  };
9
9
 
10
10
  /**
11
- * DeepSeek(深度求索)V4 系列。
12
- * 官方文档:https://api-docs.deepseek.com/guides/responses_api
11
+ * DeepSeek(深度求索)系列:V4.1 Flash 与 V4 Pro。
12
+ * 协议文档:https://api-docs.deepseek.com/guides/responses_api
13
+ * 定价依据(2026-10-16):https://api-docs.deepseek.com/zh-cn/quick_start/pricing/
14
+ * 国内高峰价(元/百万 tokens):Flash 输入/输出/命中 2/8/0.04,Pro 9/27/0.30。
15
+ * 按项目固定 0.1475 USD/CNY 折算;静态 cost 用高峰价保守估算,不按请求时间切换。
16
+ * 空闲时段为半价;高峰为北京时间工作日(不含中国法定节假日)9–12、14–18。
17
+ * cacheWrite=0 表示官方未单列附加缓存写入费用;非网关实际计费。
13
18
  */
14
19
  export function deepseekModels(root: string): ProviderModelConfig[] {
15
20
  const v1 = `${root}/v1`;
@@ -21,28 +26,7 @@ export function deepseekModels(root: string): ProviderModelConfig[] {
21
26
  baseUrl: v1,
22
27
  reasoning: true,
23
28
  input: ["text", "image"],
24
- cost: { input: 0.1475, output: 0.295, cacheRead: 0.00295, cacheWrite: 0 },
25
- contextWindow: 1000000,
26
- maxTokens: 384000,
27
- compat: DEEPSEEK_RESPONSES_COMPAT,
28
- thinkingLevelMap: {
29
- off: "none",
30
- minimal: "low",
31
- low: "low",
32
- medium: "high",
33
- high: "high",
34
- xhigh: "high",
35
- max: "max",
36
- },
37
- },
38
- {
39
- id: "deepseek-v4-flash",
40
- name: "DeepSeek V4 Flash (Legacy Alias)",
41
- api: "openai-responses",
42
- baseUrl: v1,
43
- reasoning: true,
44
- input: ["text", "image"],
45
- cost: { input: 0.1475, output: 0.295, cacheRead: 0.00295, cacheWrite: 0 },
29
+ cost: { input: 0.295, output: 1.18, cacheRead: 0.0059, cacheWrite: 0 },
46
30
  contextWindow: 1000000,
47
31
  maxTokens: 384000,
48
32
  compat: DEEPSEEK_RESPONSES_COMPAT,
@@ -64,9 +48,9 @@ export function deepseekModels(root: string): ProviderModelConfig[] {
64
48
  reasoning: true,
65
49
  input: ["text"],
66
50
  cost: {
67
- input: 0.4425,
68
- output: 0.885,
69
- cacheRead: 0.0036875,
51
+ input: 1.3275,
52
+ output: 3.9825,
53
+ cacheRead: 0.04425,
70
54
  cacheWrite: 0,
71
55
  },
72
56
  contextWindow: 1000000,
@@ -5,7 +5,7 @@ import { type PayloadWriter, type ThinkingApplier, type ThinkingLevel } from "..
5
5
  * Google Gemini 系列(google-generative-ai 协议)。
6
6
  * 官方文档:https://ai.google.dev/gemini-api/docs
7
7
  * GenerateContent 档位/预算:https://docs.cloud.google.com/vertex-ai/generative-ai/docs/thinking
8
- * 2.5 使用 budget;3.x 使用 level。网关别名的路由仍需网关侧验证。
8
+ * gemini-flash 别名保留 budget 策略,其他保留型号使用 level。网关别名的路由仍需网关侧验证。
9
9
  */
10
10
  export function geminiModels(root: string): ProviderModelConfig[] {
11
11
  const gemini = `${root}/gemini`;
@@ -68,51 +68,6 @@ export function geminiModels(root: string): ProviderModelConfig[] {
68
68
  contextWindow: 1048576,
69
69
  maxTokens: 65536,
70
70
  },
71
- {
72
- id: "gemini-3.1-pro-low",
73
- name: "Gemini 3.1 Pro Preview",
74
- api: "google-generative-ai",
75
- baseUrl: gemini,
76
- reasoning: true,
77
- input: ["text", "image"],
78
- // 网关思考档位别名(low),规格继承 gemini-3.1-pro-preview。
79
- cost: { input: 2, output: 12, cacheRead: 0.2, cacheWrite: 0 },
80
- contextWindow: 1048576,
81
- maxTokens: 65536,
82
- },
83
- {
84
- id: "gemini-2.5-pro",
85
- name: "Gemini 2.5 Pro",
86
- api: "google-generative-ai",
87
- baseUrl: gemini,
88
- reasoning: true,
89
- input: ["text", "image"],
90
- cost: { input: 1.25, output: 10, cacheRead: 0.125, cacheWrite: 0 },
91
- contextWindow: 1048576,
92
- maxTokens: 65536,
93
- },
94
- {
95
- id: "gemini-2.5-flash",
96
- name: "Gemini 2.5 Flash",
97
- api: "google-generative-ai",
98
- baseUrl: gemini,
99
- reasoning: true,
100
- input: ["text", "image"],
101
- cost: { input: 0.3, output: 2.5, cacheRead: 0.03, cacheWrite: 0 },
102
- contextWindow: 1048576,
103
- maxTokens: 65536,
104
- },
105
- {
106
- id: "gemini-2.5-flash-lite",
107
- name: "Gemini 2.5 Flash-Lite",
108
- api: "google-generative-ai",
109
- baseUrl: gemini,
110
- reasoning: true,
111
- input: ["text", "image"],
112
- cost: { input: 0.1, output: 0.4, cacheRead: 0.01, cacheWrite: 0 },
113
- contextWindow: 1048576,
114
- maxTokens: 65536,
115
- },
116
71
  ];
117
72
  }
118
73
 
@@ -137,16 +92,7 @@ function applyGeminiPro(writer: PayloadWriter, level: ThinkingLevel): void {
137
92
  writer.setGoogleThinking({ includeThoughts: level !== "off", thinkingLevel }, ["thinkingBudget"]);
138
93
  }
139
94
 
140
- // 2.5 Pro 不可关闭思考,官方 budget 范围 128..32768。
141
- // 128/16000/32768 是项目档位映射选择,并非官方档位表;off 仅隐藏摘要并取最小预算。
142
- function applyGemini25Pro(writer: PayloadWriter, level: ThinkingLevel): void {
143
- writer.remove("reasoning_effort");
144
- const thinkingBudget = level === "off" || level === "minimal" || level === "low"
145
- ? 128 : level === "max" ? 32768 : 16000;
146
- writer.setGoogleThinking({ includeThoughts: level !== "off", thinkingBudget }, ["thinkingLevel"]);
147
- }
148
-
149
- // 3.5 Flash 支持 MINIMAL/LOW/MEDIUM/HIGH,不使用 2.5 的 token budget。
95
+ // 3.5 Flash 支持 MINIMAL/LOW/MEDIUM/HIGH,不使用 token budget。
150
96
  function applyGemini35Flash(writer: PayloadWriter, level: ThinkingLevel): void {
151
97
  writer.remove("reasoning_effort");
152
98
  const thinkingLevel = level === "off" || level === "minimal" ? "MINIMAL"
@@ -159,9 +105,5 @@ export const geminiThinking: Record<string, ThinkingApplier> = {
159
105
  "gemini-3.5-flash": (w, c) => applyGemini35Flash(w, c.thinkingLevel),
160
106
  "gemini-3.5-flash-low": (w, c) => applyGemini35Flash(w, c.thinkingLevel),
161
107
  "gemini-3.5-flash-extra-low": (w, c) => applyGemini35Flash(w, c.thinkingLevel),
162
- "gemini-2.5-flash": (w, c) => applyGeminiFlash(w, c.thinkingLevel),
163
- "gemini-2.5-flash-lite": (w, c) => applyGeminiFlash(w, c.thinkingLevel),
164
108
  "gemini-pro": (w, c) => applyGeminiPro(w, c.thinkingLevel),
165
- "gemini-3.1-pro-low": (w, c) => applyGeminiPro(w, c.thinkingLevel),
166
- "gemini-2.5-pro": (w, c) => applyGemini25Pro(w, c.thinkingLevel),
167
109
  };
@@ -7,10 +7,18 @@ import { isMaximum, type PayloadWriter, type ThinkingApplier, type ThinkingLevel
7
7
  * 国内官方依据:
8
8
  * https://docs.bigmodel.cn/cn/guide/capabilities/thinking (effort 仅 5.2+)
9
9
  * https://docs.bigmodel.cn/cn/guide/capabilities/thinking-mode (保留式思考)
10
+ * 2026-10-16 5.3 / Flash / FlashX:始终思考,仅 low/high/max。
11
+ * https://docs.bigmodel.cn/cn/guide/models/text/glm-5.3
12
+ * https://docs.bigmodel.cn/cn/guide/models/vlm/glm-5.3-flash
13
+ * https://docs.bigmodel.cn/cn/guide/start/pricing
14
+ * 国内 CNY/百万 tokens 按既有固定 0.1475 USD/CNY 估算(非实时汇率);
15
+ * 三型号输入/输出/缓存命中为 8/28/2、0.8/2.8/0.23、2/7/0.57,
16
+ * 缓存存储限时免费。1M 上下文与 128K 最大输出分别登记。
10
17
  */
11
18
  export function glmModels(root: string): ProviderModelConfig[] {
12
19
  const v1 = `${root}/v1`;
13
20
  return [
21
+ ...glm53Models(v1),
14
22
  {
15
23
  id: "glm-5.2",
16
24
  name: "GLM 5.2",
@@ -30,92 +38,6 @@ export function glmModels(root: string): ProviderModelConfig[] {
30
38
  maxTokens: 131072,
31
39
  compat: OPENAI_COMPLETIONS_COMPAT,
32
40
  },
33
- {
34
- id: "glm-5.1",
35
- name: "GLM 5.1",
36
- api: "openai-completions",
37
- baseUrl: v1,
38
- reasoning: true,
39
- input: ["text"],
40
- cost: { input: 0.885, output: 3.54, cacheRead: 0.19175, cacheWrite: 0 },
41
- contextWindow: 200000,
42
- maxTokens: 65536,
43
- compat: OPENAI_COMPLETIONS_COMPAT,
44
- },
45
- {
46
- id: "glm-5",
47
- name: "GLM-5",
48
- api: "openai-completions",
49
- baseUrl: v1,
50
- reasoning: true,
51
- thinkingLevelMap: {
52
- low: "low",
53
- medium: "medium",
54
- high: "high",
55
- xhigh: "xhigh",
56
- max: "max",
57
- },
58
- input: ["text"],
59
- cost: { input: 1, output: 3.2, cacheRead: 0.2, cacheWrite: 0 },
60
- contextWindow: 200000,
61
- maxTokens: 131072,
62
- compat: OPENAI_COMPLETIONS_COMPAT,
63
- },
64
- {
65
- id: "glm-5-turbo",
66
- name: "GLM-5-Turbo",
67
- api: "openai-completions",
68
- baseUrl: v1,
69
- reasoning: true,
70
- thinkingLevelMap: {
71
- low: "low",
72
- medium: "medium",
73
- high: "high",
74
- xhigh: "xhigh",
75
- max: "max",
76
- },
77
- input: ["text"],
78
- cost: { input: 1.2, output: 4, cacheRead: 0.24, cacheWrite: 0 },
79
- contextWindow: 200000,
80
- maxTokens: 131072,
81
- compat: OPENAI_COMPLETIONS_COMPAT,
82
- },
83
- {
84
- id: "glm-4.7",
85
- name: "GLM-4.7",
86
- api: "openai-completions",
87
- baseUrl: v1,
88
- reasoning: true,
89
- input: ["text"],
90
- cost: { input: 0.6, output: 2.2, cacheRead: 0.11, cacheWrite: 0 },
91
- contextWindow: 200000,
92
- maxTokens: 131072,
93
- compat: OPENAI_COMPLETIONS_COMPAT,
94
- },
95
- {
96
- id: "glm-4.6",
97
- name: "GLM-4.6",
98
- api: "openai-completions",
99
- baseUrl: v1,
100
- reasoning: true,
101
- input: ["text"],
102
- cost: { input: 0.6, output: 2.2, cacheRead: 0.11, cacheWrite: 0 },
103
- contextWindow: 200000,
104
- maxTokens: 131072,
105
- compat: OPENAI_COMPLETIONS_COMPAT,
106
- },
107
- {
108
- id: "glm-4.5",
109
- name: "GLM-4.5",
110
- api: "openai-completions",
111
- baseUrl: v1,
112
- reasoning: true,
113
- input: ["text"],
114
- cost: { input: 0.6, output: 2.2, cacheRead: 0.11, cacheWrite: 0 },
115
- contextWindow: 128000,
116
- maxTokens: 98304,
117
- compat: OPENAI_COMPLETIONS_COMPAT,
118
- },
119
41
  {
120
42
  id: "glm-4.5-air",
121
43
  name: "GLM-4.5-Air",
@@ -131,6 +53,35 @@ export function glmModels(root: string): ProviderModelConfig[] {
131
53
  ];
132
54
  }
133
55
 
56
+ /** 5.3 三型号只有模态和价格不同;具体契约由各自官方模型页确认。 */
57
+ function glm53Models(baseUrl: string): ProviderModelConfig[] {
58
+ const variants: Pick<ProviderModelConfig, "id" | "name" | "input" | "cost">[] = [
59
+ { id: "glm-5.3", name: "GLM 5.3", input: ["text"],
60
+ cost: { input: 1.18, output: 4.13, cacheRead: 0.295, cacheWrite: 0 } },
61
+ { id: "glm-5.3-flash", name: "GLM 5.3 Flash", input: ["text", "image"],
62
+ cost: { input: 0.118, output: 0.413, cacheRead: 0.033925, cacheWrite: 0 } },
63
+ { id: "glm-5.3-flashx", name: "GLM 5.3 FlashX", input: ["text", "image"],
64
+ cost: { input: 0.295, output: 1.0325, cacheRead: 0.084075, cacheWrite: 0 } },
65
+ ];
66
+ return variants.map((model) => ({
67
+ ...model,
68
+ api: "openai-completions",
69
+ baseUrl,
70
+ reasoning: true,
71
+ thinkingLevelMap: { off: null, minimal: "low", low: "low", medium: "high", high: "high", xhigh: "max", max: "max" },
72
+ contextWindow: 1000000,
73
+ maxTokens: 131072,
74
+ compat: OPENAI_COMPLETIONS_COMPAT,
75
+ } satisfies ProviderModelConfig));
76
+ }
77
+
78
+ function applyGlm53(writer: PayloadWriter, level: ThinkingLevel): void {
79
+ if (writer.get("stream") === true) writer.set("tool_stream", true);
80
+ writer.setThinking({ type: "enabled" });
81
+ if (level === "high" || isMaximum(level)) writer.setThinking({ clear_thinking: false });
82
+ writer.set("reasoning_effort", isMaximum(level) ? "max" : level === "medium" || level === "high" ? "high" : "low");
83
+ }
84
+
134
85
  // GLM 思维链:`tool_stream=true` 仅在流式请求时附加;高级档位加 `clear_thinking=false`。
135
86
  function applyGlm(writer: PayloadWriter, level: ThinkingLevel, effort = true, preserve = true): void {
136
87
  if (!effort) writer.remove("reasoning_effort");
@@ -149,12 +100,9 @@ function applyGlm(writer: PayloadWriter, level: ThinkingLevel, effort = true, pr
149
100
  }
150
101
 
151
102
  export const glmThinking: Record<string, ThinkingApplier> = {
103
+ "glm-5.3": (w, c) => applyGlm53(w, c.thinkingLevel),
104
+ "glm-5.3-flash": (w, c) => applyGlm53(w, c.thinkingLevel),
105
+ "glm-5.3-flashx": (w, c) => applyGlm53(w, c.thinkingLevel),
152
106
  "glm-5.2": (w, c) => applyGlm(w, c.thinkingLevel),
153
- "glm-5.1": (w, c) => applyGlm(w, c.thinkingLevel, false),
154
- "glm-5": (w, c) => applyGlm(w, c.thinkingLevel, false),
155
- "glm-5-turbo": (w, c) => applyGlm(w, c.thinkingLevel, false),
156
- "glm-4.7": (w, c) => applyGlm(w, c.thinkingLevel, false),
157
- "glm-4.6": (w, c) => applyGlm(w, c.thinkingLevel, false, false),
158
- "glm-4.5": (w, c) => applyGlm(w, c.thinkingLevel, false, false),
159
107
  "glm-4.5-air": (w, c) => applyGlm(w, c.thinkingLevel, false, false),
160
108
  };
@@ -1,105 +1,43 @@
1
1
  import type { ChatModelConfig as ProviderModelConfig } from "../_tools.ts";
2
2
  import { OPENAI_COMPLETIONS_COMPAT } from "./_protocols.ts";
3
- import { applyEnabledThinking, type PayloadWriter, type ThinkingApplier, type ThinkingLevel } from "../_tools.ts";
3
+ import { type PayloadWriter, type ThinkingApplier, type ThinkingLevel } from "../_tools.ts";
4
4
 
5
5
  /**
6
- * 月之暗面(Moonshot)Kimi 系列。
7
- * 官方文档:https://platform.moonshot.cn/docs
8
- * K2.7 Code 参数:https://platform.moonshot.cn/docs/api/models-overview
6
+ * 月之暗面(Moonshot)Kimi K3 系列。
7
+ * 官方文档:https://platform.kimi.ai/docs/guide/kimi-k3-quickstart
8
+ * 思考档位:https://platform.kimi.ai/docs/guide/use-reasoning-effort
9
+ * kimi-k3-256k 是网关变体:按已确认约定将上下文限制为 256 * 1024,
10
+ * 其余元数据/价格估算沿用 K3,不代表该变体已逐项通过端点验证。
11
+ * maxTokens 保留既有 131072,并非把 256K 上下文当成最大输出。
9
12
  */
10
13
  export function kimiModels(root: string): ProviderModelConfig[] {
11
- const v1 = `${root}/v1`;
12
- return [
13
- {
14
- id: "kimi-for-coding",
15
- name: "Kimi K2.7 Code",
16
- api: "openai-completions",
17
- baseUrl: v1,
18
- reasoning: true,
19
- input: ["text", "image"],
20
- cost: {
21
- input: 0.95875,
22
- output: 3.9825,
23
- cacheRead: 0.19175,
24
- cacheWrite: 0,
25
- },
26
- contextWindow: 262144,
27
- maxTokens: 32768,
28
- compat: OPENAI_COMPLETIONS_COMPAT,
29
- },
30
- {
31
- id: "kimi-k3",
32
- name: "Kimi K3",
33
- api: "openai-completions",
34
- baseUrl: v1,
35
- reasoning: true,
36
- thinkingLevelMap: {
37
- off: null,
38
- low: "low",
39
- medium: "medium",
40
- high: "high",
41
- xhigh: "xhigh",
42
- max: "max",
43
- },
44
- input: ["text", "image"],
45
- cost: { input: 3, output: 15, cacheRead: 2, cacheWrite: 0 },
46
- contextWindow: 1000000,
47
- maxTokens: 131072,
48
- compat: OPENAI_COMPLETIONS_COMPAT,
49
- },
50
- {
51
- id: "kimi-k2.7-code",
52
- name: "Kimi K2.7 Code",
53
- api: "openai-completions",
54
- baseUrl: v1,
55
- reasoning: true,
56
- thinkingLevelMap: { off: null },
57
- input: ["text", "image"],
58
- cost: { input: 0.95, output: 4, cacheRead: 0.19, cacheWrite: 0 },
59
- contextWindow: 262144,
60
- // 兼容性暂存值:独立输出上限未确认,并非官方确认的输出规格。
61
- maxTokens: 262144,
62
- compat: OPENAI_COMPLETIONS_COMPAT,
63
- },
64
- {
65
- id: "kimi-k2.7-code-highspeed",
66
- name: "Kimi K2.7 Code HighSpeed",
67
- api: "openai-completions",
68
- baseUrl: v1,
69
- reasoning: true,
70
- thinkingLevelMap: { off: null },
71
- input: ["text", "image"],
72
- cost: { input: 1.9, output: 8, cacheRead: 0.38, cacheWrite: 0 },
73
- contextWindow: 262144,
74
- // 兼容性暂存值:独立输出上限未确认,并非官方确认的输出规格。
75
- maxTokens: 262144,
76
- compat: OPENAI_COMPLETIONS_COMPAT,
77
- },
78
- {
79
- id: "kimi-k2.6",
80
- name: "Kimi K2.6",
81
- api: "openai-completions",
82
- baseUrl: v1,
83
- reasoning: true,
84
- input: ["text", "image"],
85
- cost: { input: 0.95, output: 4, cacheRead: 0.16, cacheWrite: 0 },
86
- contextWindow: 262144,
87
- // 兼容性暂存值:独立输出上限未确认,并非官方确认的输出规格。
88
- maxTokens: 262144,
89
- compat: OPENAI_COMPLETIONS_COMPAT,
14
+ const k3: ProviderModelConfig = {
15
+ id: "kimi-k3",
16
+ name: "Kimi K3",
17
+ api: "openai-completions",
18
+ baseUrl: `${root}/v1`,
19
+ reasoning: true,
20
+ thinkingLevelMap: {
21
+ off: null,
22
+ low: "low",
23
+ medium: "medium",
24
+ high: "high",
25
+ xhigh: "xhigh",
26
+ max: "max",
90
27
  },
28
+ input: ["text", "image"],
29
+ cost: { input: 3, output: 15, cacheRead: 2, cacheWrite: 0 },
30
+ contextWindow: 1000000,
31
+ maxTokens: 131072,
32
+ compat: OPENAI_COMPLETIONS_COMPAT,
33
+ };
34
+ return [
35
+ k3,
91
36
  {
92
- id: "kimi-k2.5",
93
- name: "Kimi K2.5",
94
- api: "openai-completions",
95
- baseUrl: v1,
96
- reasoning: true,
97
- input: ["text", "image"],
98
- cost: { input: 0.6, output: 3, cacheRead: 0.1, cacheWrite: 0 },
37
+ ...k3,
38
+ id: "kimi-k3-256k",
39
+ name: "Kimi K3 (256K)",
99
40
  contextWindow: 262144,
100
- // 兼容性暂存值:独立输出上限未确认,并非官方确认的输出规格。
101
- maxTokens: 262144,
102
- compat: OPENAI_COMPLETIONS_COMPAT,
103
41
  },
104
42
  ];
105
43
  }
@@ -115,17 +53,7 @@ function applyKimiK3(writer: PayloadWriter, level: ThinkingLevel): void {
115
53
  writer.set("reasoning_effort", level === "max" ? "max" : "high");
116
54
  }
117
55
 
118
- // canonical Code 与 highspeed 为同模型:不可关闭,显式 thinking 仅接受此组合。
119
- function applyKimiCode(writer: PayloadWriter): void {
120
- writer.remove("reasoning_effort");
121
- writer.setThinking({ type: "enabled", keep: "all" });
122
- }
123
-
124
56
  export const kimiThinking: Record<string, ThinkingApplier> = {
125
- "kimi-for-coding": (w, c) => applyEnabledThinking(w, c.thinkingLevel),
126
57
  "kimi-k3": (w, c) => applyKimiK3(w, c.thinkingLevel),
127
- "kimi-k2.7-code": (w) => applyKimiCode(w),
128
- "kimi-k2.7-code-highspeed": (w) => applyKimiCode(w),
129
- "kimi-k2.6": (w, c) => applyEnabledThinking(w, c.thinkingLevel),
130
- "kimi-k2.5": (w, c) => applyEnabledThinking(w, c.thinkingLevel),
58
+ "kimi-k3-256k": (w, c) => applyKimiK3(w, c.thinkingLevel),
131
59
  };