pi-tsgw 0.0.11 → 0.0.12
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 +65 -29
- package/extensions/index.ts +7 -4
- package/extensions/models/_tools.ts +9 -3
- package/extensions/models/catalog.ts +1 -1
- package/extensions/models/gateway-catalog.ts +66 -20
- package/extensions/models/vendors/_protocols.ts +1 -1
- package/extensions/models/vendors/anthropic.ts +1 -1
- package/extensions/models/vendors/deepseek.ts +1 -1
- package/extensions/models/vendors/gemini.ts +25 -6
- package/extensions/models/vendors/glm.ts +16 -13
- package/extensions/models/vendors/grok.ts +5 -3
- package/extensions/models/vendors/kimi.ts +19 -12
- package/extensions/models/vendors/longcat.ts +1 -1
- package/extensions/models/vendors/mimo.ts +1 -1
- package/extensions/models/vendors/minimax.ts +15 -10
- package/extensions/models/vendors/openai.ts +1 -1
- package/extensions/models/vendors/qwen.ts +1 -1
- package/extensions/models/web-search.ts +4 -4
- package/extensions/status.ts +1 -2
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -6,8 +6,9 @@ openai-responses, anthropic-messages, google-generative-ai) and applies
|
|
|
6
6
|
per-vendor request-body operations so thinking levels, reasoning formats, and
|
|
7
7
|
optional built-in web search behave correctly on the gateway.
|
|
8
8
|
|
|
9
|
-
No API keys
|
|
10
|
-
|
|
9
|
+
No private API keys or gateway endpoints are included. The static catalog
|
|
10
|
+
contains model metadata and public-price estimates; these are not your gateway's
|
|
11
|
+
billing rates.
|
|
11
12
|
|
|
12
13
|
## Install
|
|
13
14
|
|
|
@@ -36,7 +37,7 @@ Example:
|
|
|
36
37
|
{
|
|
37
38
|
"tsgw": {
|
|
38
39
|
"baseUrl": "https://aih.example.net",
|
|
39
|
-
"tsSearch": "
|
|
40
|
+
"tsSearch": "live",
|
|
40
41
|
"traceHeaders": false,
|
|
41
42
|
"excludeModels": ["gpt-*", "claude-*"],
|
|
42
43
|
"includeModels": ["gpt-5.6-*"]
|
|
@@ -52,19 +53,23 @@ placeholder root is used that will not work.
|
|
|
52
53
|
|
|
53
54
|
### API key
|
|
54
55
|
|
|
55
|
-
The extension
|
|
56
|
+
The extension delegates credential reading and resolution to Pi:
|
|
56
57
|
|
|
57
58
|
1. **`/login`** — select the `tsgw` provider and enter the key; pi stores it
|
|
58
59
|
in `~/.pi/agent/auth.json` (preferred)
|
|
59
60
|
2. **`TSGW_API_KEY`** environment variable — Pi's fallback when nothing is
|
|
60
61
|
stored
|
|
61
62
|
|
|
63
|
+
Startup discovery uses Pi's stored-credential API; later catalog refreshes use
|
|
64
|
+
the credential supplied by Pi. With environment-only authentication, the initial
|
|
65
|
+
catalog may fall back to static models until Pi refreshes it.
|
|
66
|
+
|
|
62
67
|
### Options
|
|
63
68
|
|
|
64
69
|
| Setting (`settings.json` `tsgw.*`) | Default | Meaning |
|
|
65
70
|
| --- | --- | --- |
|
|
66
71
|
| `baseUrl` | placeholder | Gateway root (the `/v1` suffix is normalized away) |
|
|
67
|
-
| `tsSearch` | `
|
|
72
|
+
| `tsSearch` | `live` | GPT: `cached` or `live`; unset, legacy `off`, and invalid values fall back to `live`. Supported Grok models always use live search. |
|
|
68
73
|
| `traceHeaders` | `false` | Adds `AH-Thread-Id` / `AH-Trace-Id` headers for gateway-side tracing |
|
|
69
74
|
| `includeModels` | unset | Re-include override: matching model ids are kept even when also matched by `excludeModels` (exact id or `prefix-*` glob) |
|
|
70
75
|
| `excludeModels` | unset | Blacklist: matching model ids are dropped unless pulled back by `includeModels` (exact id or `prefix-*` glob) |
|
|
@@ -72,42 +77,63 @@ The extension never reads credential files. Pi resolves the key itself:
|
|
|
72
77
|
## Model catalog
|
|
73
78
|
|
|
74
79
|
The catalog is assembled from per-vendor slices (`extensions/models/vendors/`),
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
80
|
+
covering 11 vendor families: DeepSeek, GLM (Zhipu), MiMo (Xiaomi), MiniMax,
|
|
81
|
+
Kimi (Moonshot), Qwen (Alibaba), GPT (OpenAI), Gemini (Google), Claude
|
|
82
|
+
(Anthropic), LongCat, and Grok (xAI). The current static catalog contains 54 chat
|
|
83
|
+
model IDs, including retained aliases; this is not a live availability count.
|
|
84
|
+
Vendor files carry documentation links and metadata caveats. Alias mappings,
|
|
85
|
+
output limits, and shared thinking policies are not all individually verified
|
|
86
|
+
against gateway endpoints; public-price estimates do not guarantee billing.
|
|
81
87
|
|
|
82
88
|
Use broad `excludeModels` rules to drop model families and precise
|
|
83
89
|
`includeModels` rules to pull selected models back. `includeModels` is not a
|
|
84
90
|
global whitelist: models matching neither list remain available. To register
|
|
85
91
|
only selected models, use `"excludeModels": ["*"]` and pull them back through
|
|
86
|
-
`includeModels`.
|
|
92
|
+
`includeModels`. Both lists are case-sensitive and support only exact IDs or
|
|
93
|
+
trailing `*` prefix matching (not general globs); preserve `MiniMax-*` casing.
|
|
94
|
+
When a gateway catalog is available, filtering applies after intersecting it
|
|
95
|
+
with the static catalog. Include rules cannot add unknown or unavailable IDs.
|
|
87
96
|
|
|
88
97
|
Opening `/model` refreshes the gateway catalog in the background, with a
|
|
89
98
|
five-minute cache to avoid repeated requests. Run `/tsgw-refresh` to bypass the
|
|
90
99
|
cache and force an immediate refresh without restarting or reloading Pi. If a
|
|
91
100
|
refresh fails, the last successful model list remains active.
|
|
92
101
|
|
|
102
|
+
Memory and disk caches are scoped to the gateway root and credential using a
|
|
103
|
+
SHA-256 digest; plaintext credentials are not stored. The disk cache is a single
|
|
104
|
+
slot at `<agent-dir>/tsgw/models-cache.json`: changing scope may require a fresh
|
|
105
|
+
fetch. Legacy unscoped cache files are ignored and replaced after a successful
|
|
106
|
+
fetch. In-process request ordering prevents late results from replacing newer
|
|
107
|
+
cache writes; this is not a cross-process locking mechanism.
|
|
108
|
+
|
|
93
109
|
## Status bar and session controls
|
|
94
110
|
|
|
95
|
-
Pi Web
|
|
111
|
+
Pi Web clients supporting `command:/…` statuses render these as clickable
|
|
112
|
+
buttons; the terminal CLI displays status text and accepts the same commands:
|
|
96
113
|
|
|
97
114
|
- **`TSGW · N`** (`/tsgw`): one menu for **refreshing the model catalog** and
|
|
98
115
|
**viewing diagnostics**. The count is the filtered registered catalog, not a
|
|
99
116
|
count of healthy inference endpoints. 🟢 means a fresh directory result;
|
|
100
117
|
🟡 means a static/expired directory or a failed refresh; ⚠️ means missing
|
|
101
118
|
credentials or gateway configuration; ⏳ means a refresh is running.
|
|
102
|
-
- **Built-in search** (`/tsgw-search`):
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
hidden when another provider is selected.
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
across a reload or a new session; `tsgw.tsSearch` remains the startup
|
|
119
|
+
- **Built-in search** (`/tsgw-search`): GPT offers only `cached / live`
|
|
120
|
+
for the current session, defaulting to `live`. Supported Grok models use
|
|
121
|
+
fixed live search: the command only shows a notice, without a picker or
|
|
122
|
+
changing the GPT session mode. Unsupported TSGW models are labeled
|
|
123
|
+
accordingly; this button is hidden when another provider is selected.
|
|
124
|
+
|
|
125
|
+
For GPT, you can also type `/tsgw-search cached` or `/tsgw-search live`;
|
|
126
|
+
`off` is no longer accepted. These controls do not modify `settings.json` or
|
|
127
|
+
persist across a reload or a new session; `tsgw.tsSearch` remains the startup
|
|
128
|
+
default. Existing `cached` configuration is preserved; unset, legacy `off`,
|
|
129
|
+
and invalid configuration now default to `live`.
|
|
130
|
+
|
|
131
|
+
Injection remains limited to the existing model/protocol support list. GPT
|
|
132
|
+
Responses appends a `web_search` tool (`external_web_access` is false for
|
|
133
|
+
`cached`, true for `live`); Grok Completions appends
|
|
134
|
+
`search_parameters: { mode: "on" }`. Existing search tools/fields are never
|
|
135
|
+
overwritten. This setting does not control Qwen's vendor policy, external
|
|
136
|
+
tools, or thinking mode and is not a global network-access switch.
|
|
111
137
|
|
|
112
138
|
The standalone `ts_search` tool is no longer bundled. Use a separately configured
|
|
113
139
|
search tool such as `ts_oht.search` instead. Built-in model search remains
|
|
@@ -126,16 +152,26 @@ statuses until the session runtime has started.
|
|
|
126
152
|
## Development
|
|
127
153
|
|
|
128
154
|
```bash
|
|
129
|
-
npm
|
|
155
|
+
npm ci
|
|
130
156
|
npm test
|
|
157
|
+
npm exec -- tsc -p tsconfig.json
|
|
158
|
+
npm pack --dry-run --json
|
|
131
159
|
```
|
|
132
160
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
161
|
+
Pi is installed as a development dependency; the lockfile defines the test
|
|
162
|
+
baseline. Tests isolate configuration and credentials using temporary agent
|
|
163
|
+
directories. Unit tests use a fake host; host integration tests load the extension
|
|
164
|
+
through the real Pi SDK with simulated HTTP responses, without production
|
|
165
|
+
requests. They do not verify upstream inference, native search results, or Pi
|
|
166
|
+
Web rendering. Run the full suite after upgrading Pi.
|
|
136
167
|
|
|
137
168
|
## Technical details
|
|
138
169
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
[
|
|
170
|
+
- [Vendor profiles](https://github.com/tossp/pi-tsgw/tree/main/extensions/models/vendors): model metadata, compatibility flags, and thinking mappings.
|
|
171
|
+
- [Request operations](https://github.com/tossp/pi-tsgw/blob/main/extensions/models/operations.ts): copy-on-write dispatch; DeepSeek/Claude response handling stays with Pi's adapters.
|
|
172
|
+
- [Built-in search](https://github.com/tossp/pi-tsgw/blob/main/extensions/models/web-search.ts): exact model/protocol support and append-only injection.
|
|
173
|
+
- [Host integration](https://github.com/tossp/pi-tsgw/blob/main/extensions/index.ts): configuration, refreshes, commands, and lifecycle snapshots. Late request callbacks must not access stale session contexts.
|
|
174
|
+
|
|
175
|
+
These source links describe the repository's current main branch; an installed
|
|
176
|
+
release may differ. Development rules in `AGENTS.md` are repository-only and
|
|
177
|
+
are not part of the npm package.
|
package/extensions/index.ts
CHANGED
|
@@ -200,7 +200,7 @@ export default async function registerTsgw(pi: ExtensionAPI): Promise<void> {
|
|
|
200
200
|
const defaultSearchMode: WebSearchMode =
|
|
201
201
|
settings.tsSearch === "cached" || settings.tsSearch === "live"
|
|
202
202
|
? settings.tsSearch
|
|
203
|
-
: "
|
|
203
|
+
: "live";
|
|
204
204
|
let tsSearchMode = defaultSearchMode;
|
|
205
205
|
const traceEnabled = settings.traceHeaders === true;
|
|
206
206
|
const modelFilter: ModelFilter = {
|
|
@@ -383,8 +383,11 @@ export default async function registerTsgw(pi: ExtensionAPI): Promise<void> {
|
|
|
383
383
|
ctx.ui.notify("当前模型不支持插件内置联网。", "info");
|
|
384
384
|
return;
|
|
385
385
|
}
|
|
386
|
-
|
|
387
|
-
|
|
386
|
+
if (support === "grok") {
|
|
387
|
+
ctx.ui.notify("当前 Grok 模型内置联网固定为实时;不修改 GPT 会话模式。", "info");
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
const modes: WebSearchMode[] = ["cached", "live"];
|
|
388
391
|
const labels = modes.map((mode) => searchLabel(mode, support));
|
|
389
392
|
const input = args.trim();
|
|
390
393
|
const choice = input || (ctx.hasUI
|
|
@@ -396,7 +399,7 @@ export default async function registerTsgw(pi: ExtensionAPI): Promise<void> {
|
|
|
396
399
|
}
|
|
397
400
|
const mode = modes.find((mode, index) => mode === choice || labels[index] === choice);
|
|
398
401
|
if (!mode) {
|
|
399
|
-
ctx.ui.notify("不支持的模式;GPT
|
|
402
|
+
ctx.ui.notify("不支持的模式;GPT 仅支持 cached/live,Grok 固定实时。", "warning");
|
|
400
403
|
return;
|
|
401
404
|
}
|
|
402
405
|
tsSearchMode = mode;
|
|
@@ -5,6 +5,12 @@
|
|
|
5
5
|
* 与 operations 调度都从这里引用,避免 vendors ↔ operations 循环依赖。
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import type { ProviderModelConfig } from "@earendil-works/pi-coding-agent";
|
|
9
|
+
|
|
10
|
+
// Pi 1.x also includes image/classifier configs; this catalog is chat-only.
|
|
11
|
+
// Structural extraction keeps compatibility with the older chat-only type.
|
|
12
|
+
export type ChatModelConfig = Extract<ProviderModelConfig, { reasoning: boolean }>;
|
|
13
|
+
|
|
8
14
|
export type ThinkingLevel =
|
|
9
15
|
| "off"
|
|
10
16
|
| "minimal"
|
|
@@ -13,7 +19,7 @@ export type ThinkingLevel =
|
|
|
13
19
|
| "high"
|
|
14
20
|
| "xhigh"
|
|
15
21
|
| "max";
|
|
16
|
-
export type WebSearchMode = "
|
|
22
|
+
export type WebSearchMode = "cached" | "live";
|
|
17
23
|
|
|
18
24
|
export interface ModelOperationContext {
|
|
19
25
|
provider: string;
|
|
@@ -28,7 +34,7 @@ type GoogleThinkingField =
|
|
|
28
34
|
| "includeThoughts"
|
|
29
35
|
| "thinkingLevel"
|
|
30
36
|
| "thinkingBudget";
|
|
31
|
-
type ThinkingUpdate = Partial<Pick<Payload, "type" | "clear_thinking">>;
|
|
37
|
+
type ThinkingUpdate = Partial<Pick<Payload, "type" | "clear_thinking" | "keep">>;
|
|
32
38
|
type GoogleThinkingUpdate = Partial<Pick<Payload, GoogleThinkingField>>;
|
|
33
39
|
|
|
34
40
|
export function isPlainObject(value: unknown): value is Payload {
|
|
@@ -109,7 +115,7 @@ export class PayloadWriter {
|
|
|
109
115
|
}
|
|
110
116
|
}
|
|
111
117
|
|
|
112
|
-
const THINKING_FIELDS = ["type", "clear_thinking"] as const;
|
|
118
|
+
const THINKING_FIELDS = ["type", "clear_thinking", "keep"] as const;
|
|
113
119
|
const GOOGLE_THINKING_FIELDS = [
|
|
114
120
|
"includeThoughts",
|
|
115
121
|
"thinkingLevel",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ProviderModelConfig } from "
|
|
1
|
+
import type { ChatModelConfig as ProviderModelConfig } from "./_tools.ts";
|
|
2
2
|
import { anthropicModels } from "./vendors/anthropic.ts";
|
|
3
3
|
import { deepseekModels } from "./vendors/deepseek.ts";
|
|
4
4
|
import { geminiModels } from "./vendors/gemini.ts";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
2
|
import {
|
|
3
3
|
mkdirSync,
|
|
4
4
|
readFileSync,
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
unlinkSync,
|
|
7
7
|
writeFileSync,
|
|
8
8
|
} from "node:fs";
|
|
9
|
-
import { dirname } from "node:path";
|
|
9
|
+
import { dirname, resolve } from "node:path";
|
|
10
10
|
|
|
11
11
|
export const DEFAULT_GATEWAY_MODEL_TIMEOUT_MS = 5_000;
|
|
12
12
|
export const DEFAULT_GATEWAY_MODEL_CACHE_TTL_MS = 5 * 60 * 1_000;
|
|
@@ -126,6 +126,8 @@ export async function fetchGatewayModelIds(
|
|
|
126
126
|
return { ok: false, reason: "network", detail: errorDetail(error) };
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
+
if (timedOut) return { ok: false, reason: "timeout" };
|
|
130
|
+
if (opts.signal?.aborted) return { ok: false, reason: "aborted" };
|
|
129
131
|
if (!response.ok) {
|
|
130
132
|
return { ok: false, reason: "http", status: response.status };
|
|
131
133
|
}
|
|
@@ -139,6 +141,8 @@ export async function fetchGatewayModelIds(
|
|
|
139
141
|
return { ok: false, reason: "invalid-json", detail: errorDetail(error) };
|
|
140
142
|
}
|
|
141
143
|
|
|
144
|
+
if (timedOut) return { ok: false, reason: "timeout" };
|
|
145
|
+
if (opts.signal?.aborted) return { ok: false, reason: "aborted" };
|
|
142
146
|
if (!payload || typeof payload !== "object")
|
|
143
147
|
return { ok: false, reason: "invalid-data" };
|
|
144
148
|
const data = (payload as { data?: unknown }).data;
|
|
@@ -176,17 +180,27 @@ export function createModelCache(
|
|
|
176
180
|
};
|
|
177
181
|
}
|
|
178
182
|
|
|
183
|
+
/** Hash both identity components; no plaintext credentials in cache keys or files. */
|
|
184
|
+
export function gatewayModelCacheScope(baseUrl: string, apiKey: string): string {
|
|
185
|
+
return createHash("sha256")
|
|
186
|
+
.update(JSON.stringify([baseUrl.replace(/\/+$/, ""), apiKey]))
|
|
187
|
+
.digest("hex");
|
|
188
|
+
}
|
|
189
|
+
|
|
179
190
|
function readGatewayModelCacheEntry(
|
|
180
191
|
filePath: string,
|
|
192
|
+
scope: string,
|
|
181
193
|
): ModelCacheEntry | undefined {
|
|
182
194
|
try {
|
|
183
195
|
const payload: unknown = JSON.parse(readFileSync(filePath, "utf8"));
|
|
184
196
|
if (!payload || typeof payload !== "object") return undefined;
|
|
185
|
-
const { storedAt, ids } = payload as {
|
|
197
|
+
const { storedAt, ids, scope: storedScope } = payload as {
|
|
198
|
+
scope?: unknown;
|
|
186
199
|
storedAt?: unknown;
|
|
187
200
|
ids?: unknown;
|
|
188
201
|
};
|
|
189
202
|
if (
|
|
203
|
+
!scope || storedScope !== scope ||
|
|
190
204
|
typeof storedAt !== "number" ||
|
|
191
205
|
!Number.isFinite(storedAt) ||
|
|
192
206
|
storedAt < 0 ||
|
|
@@ -214,6 +228,7 @@ function isCacheEntryFresh(
|
|
|
214
228
|
/** Atomically persist gateway model IDs. Write failures are non-fatal. */
|
|
215
229
|
export function saveGatewayModelCache(
|
|
216
230
|
filePath: string,
|
|
231
|
+
scope: string,
|
|
217
232
|
ids: readonly string[],
|
|
218
233
|
now = Date.now(),
|
|
219
234
|
): void {
|
|
@@ -222,7 +237,7 @@ export function saveGatewayModelCache(
|
|
|
222
237
|
mkdirSync(dirname(filePath), { recursive: true });
|
|
223
238
|
writeFileSync(
|
|
224
239
|
temporaryPath,
|
|
225
|
-
JSON.stringify({ storedAt: now, ids: [...ids] }),
|
|
240
|
+
JSON.stringify({ scope, storedAt: now, ids: [...ids] }),
|
|
226
241
|
{ encoding: "utf8", mode: 0o600 },
|
|
227
242
|
);
|
|
228
243
|
renameSync(temporaryPath, filePath);
|
|
@@ -238,12 +253,13 @@ export function saveGatewayModelCache(
|
|
|
238
253
|
/** Load a persisted gateway model list. Missing or invalid files are ignored. */
|
|
239
254
|
export function loadGatewayModelCache(
|
|
240
255
|
filePath: string,
|
|
256
|
+
scope: string,
|
|
241
257
|
now = Date.now(),
|
|
242
258
|
ttlMs = DEFAULT_GATEWAY_MODEL_CACHE_TTL_MS,
|
|
243
259
|
): LoadedGatewayModelCache | undefined {
|
|
244
260
|
if (!Number.isFinite(ttlMs) || ttlMs < 0)
|
|
245
261
|
throw new RangeError("ttlMs must be a non-negative finite number");
|
|
246
|
-
const entry = readGatewayModelCacheEntry(filePath);
|
|
262
|
+
const entry = readGatewayModelCacheEntry(filePath, scope);
|
|
247
263
|
if (!entry) return undefined;
|
|
248
264
|
return {
|
|
249
265
|
ids: [...entry.ids],
|
|
@@ -252,10 +268,18 @@ export function loadGatewayModelCache(
|
|
|
252
268
|
}
|
|
253
269
|
|
|
254
270
|
const gatewayCaches = new Map<string, ModelCache>();
|
|
255
|
-
|
|
271
|
+
interface PendingRequest {
|
|
272
|
+
promise: Promise<FetchGatewayModelIdsResult>;
|
|
273
|
+
revision: number;
|
|
274
|
+
storedAt: number;
|
|
275
|
+
}
|
|
276
|
+
const inFlightRequests = new Map<string, PendingRequest>();
|
|
277
|
+
const latestRequests = new Map<string, number>();
|
|
278
|
+
// Disk is single-slot per normalized path, independently of the memory scope.
|
|
279
|
+
const latestDiskRequests = new Map<string, number>();
|
|
280
|
+
let revision = 0;
|
|
256
281
|
|
|
257
|
-
function cacheFor(
|
|
258
|
-
const key = baseUrl.replace(/\/+$/, "");
|
|
282
|
+
function cacheFor(key: string): ModelCache {
|
|
259
283
|
let cache = gatewayCaches.get(key);
|
|
260
284
|
if (!cache) {
|
|
261
285
|
cache = createModelCache();
|
|
@@ -276,7 +300,8 @@ export async function getGatewayModelIds(
|
|
|
276
300
|
opts: GetGatewayModelIdsOptions = {},
|
|
277
301
|
now = Date.now(),
|
|
278
302
|
): Promise<GetGatewayModelIdsResult> {
|
|
279
|
-
|
|
303
|
+
if (opts.signal?.aborted) return { ok: false, reason: "aborted" };
|
|
304
|
+
const key = gatewayModelCacheScope(baseUrl, apiKey);
|
|
280
305
|
const cache = cacheFor(key);
|
|
281
306
|
if (!opts.force && cache.isFresh(now)) {
|
|
282
307
|
const entry = cache.get();
|
|
@@ -291,7 +316,7 @@ export async function getGatewayModelIds(
|
|
|
291
316
|
}
|
|
292
317
|
|
|
293
318
|
const diskEntry = opts.cacheFilePath
|
|
294
|
-
? readGatewayModelCacheEntry(opts.cacheFilePath)
|
|
319
|
+
? readGatewayModelCacheEntry(opts.cacheFilePath, key)
|
|
295
320
|
: undefined;
|
|
296
321
|
if (
|
|
297
322
|
!opts.force &&
|
|
@@ -315,32 +340,53 @@ export async function getGatewayModelIds(
|
|
|
315
340
|
const shareRequest = opts.signal === undefined;
|
|
316
341
|
let request = shareRequest ? inFlightRequests.get(requestKey) : undefined;
|
|
317
342
|
if (!request) {
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
343
|
+
const requestRevision = ++revision;
|
|
344
|
+
latestRequests.set(key, requestRevision);
|
|
345
|
+
request = {
|
|
346
|
+
revision: requestRevision,
|
|
347
|
+
storedAt: now,
|
|
348
|
+
promise: fetchGatewayModelIds(baseUrl, apiKey, {
|
|
349
|
+
fetcher: opts.fetcher,
|
|
350
|
+
timeoutMs: opts.timeoutMs,
|
|
351
|
+
signal: opts.signal,
|
|
352
|
+
}),
|
|
353
|
+
};
|
|
323
354
|
if (shareRequest) inFlightRequests.set(requestKey, request);
|
|
324
355
|
}
|
|
325
356
|
|
|
357
|
+
const diskPath = opts.cacheFilePath ? resolve(opts.cacheFilePath) : undefined;
|
|
358
|
+
if (diskPath) {
|
|
359
|
+
// Register every subscriber's path, including shared requests with different
|
|
360
|
+
// destinations. Joining an older request must not roll back a newer fence.
|
|
361
|
+
latestDiskRequests.set(diskPath, Math.max(
|
|
362
|
+
latestDiskRequests.get(diskPath) ?? 0, request.revision,
|
|
363
|
+
));
|
|
364
|
+
}
|
|
365
|
+
|
|
326
366
|
let fetched: FetchGatewayModelIdsResult;
|
|
327
367
|
try {
|
|
328
|
-
fetched = await request;
|
|
368
|
+
fetched = await request.promise;
|
|
329
369
|
} finally {
|
|
330
370
|
if (shareRequest && inFlightRequests.get(requestKey) === request)
|
|
331
371
|
inFlightRequests.delete(requestKey);
|
|
332
372
|
}
|
|
333
373
|
|
|
374
|
+
// Cancellation never falls back or writes, even if a fetcher ignores its signal.
|
|
375
|
+
if (opts.signal?.aborted) return { ok: false, reason: "aborted" };
|
|
334
376
|
if (fetched.ok) {
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
377
|
+
// Latest-started wins even if the newer request fails or aborts.
|
|
378
|
+
// Superseded successes still return to their callers without cache writes.
|
|
379
|
+
if (latestRequests.get(key) === request.revision) {
|
|
380
|
+
cache.set(fetched.ids, request.storedAt);
|
|
381
|
+
if (diskPath && latestDiskRequests.get(diskPath) === request.revision)
|
|
382
|
+
saveGatewayModelCache(diskPath, key, fetched.ids, request.storedAt);
|
|
383
|
+
}
|
|
338
384
|
return {
|
|
339
385
|
ok: true,
|
|
340
386
|
ids: [...fetched.ids],
|
|
341
387
|
cached: false,
|
|
342
388
|
stale: false,
|
|
343
|
-
storedAt:
|
|
389
|
+
storedAt: request.storedAt,
|
|
344
390
|
};
|
|
345
391
|
}
|
|
346
392
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ProviderModelConfig } from "
|
|
1
|
+
import type { ChatModelConfig as ProviderModelConfig } from "../_tools.ts";
|
|
2
2
|
|
|
3
3
|
// DeepSeek Responses 将 developer role 当作 user,且不支持 OpenAI 的
|
|
4
4
|
// prompt_cache_retention;其余 reasoning 字段交给 Pi 的 Responses adapter。
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import type { ProviderModelConfig } from "
|
|
2
|
-
import {
|
|
1
|
+
import type { ChatModelConfig as ProviderModelConfig } from "../_tools.ts";
|
|
2
|
+
import { type PayloadWriter, type ThinkingApplier, type ThinkingLevel } from "../_tools.ts";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Google Gemini 系列(google-generative-ai 协议)。
|
|
6
6
|
* 官方文档:https://ai.google.dev/gemini-api/docs
|
|
7
|
+
* GenerateContent 档位/预算:https://docs.cloud.google.com/vertex-ai/generative-ai/docs/thinking
|
|
8
|
+
* 2.5 使用 budget;3.x 使用 level。网关别名的路由仍需网关侧验证。
|
|
7
9
|
*/
|
|
8
10
|
export function geminiModels(root: string): ProviderModelConfig[] {
|
|
9
11
|
const gemini = `${root}/gemini`;
|
|
@@ -135,14 +137,31 @@ function applyGeminiPro(writer: PayloadWriter, level: ThinkingLevel): void {
|
|
|
135
137
|
writer.setGoogleThinking({ includeThoughts: level !== "off", thinkingLevel }, ["thinkingBudget"]);
|
|
136
138
|
}
|
|
137
139
|
|
|
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。
|
|
150
|
+
function applyGemini35Flash(writer: PayloadWriter, level: ThinkingLevel): void {
|
|
151
|
+
writer.remove("reasoning_effort");
|
|
152
|
+
const thinkingLevel = level === "off" || level === "minimal" ? "MINIMAL"
|
|
153
|
+
: level === "low" ? "LOW" : level === "medium" ? "MEDIUM" : "HIGH";
|
|
154
|
+
writer.setGoogleThinking({ includeThoughts: level !== "off", thinkingLevel }, ["thinkingBudget"]);
|
|
155
|
+
}
|
|
156
|
+
|
|
138
157
|
export const geminiThinking: Record<string, ThinkingApplier> = {
|
|
139
158
|
"gemini-flash": (w, c) => applyGeminiFlash(w, c.thinkingLevel),
|
|
140
|
-
"gemini-3.5-flash": (w, c) =>
|
|
141
|
-
"gemini-3.5-flash-low": (w, c) =>
|
|
142
|
-
"gemini-3.5-flash-extra-low": (w, c) =>
|
|
159
|
+
"gemini-3.5-flash": (w, c) => applyGemini35Flash(w, c.thinkingLevel),
|
|
160
|
+
"gemini-3.5-flash-low": (w, c) => applyGemini35Flash(w, c.thinkingLevel),
|
|
161
|
+
"gemini-3.5-flash-extra-low": (w, c) => applyGemini35Flash(w, c.thinkingLevel),
|
|
143
162
|
"gemini-2.5-flash": (w, c) => applyGeminiFlash(w, c.thinkingLevel),
|
|
144
163
|
"gemini-2.5-flash-lite": (w, c) => applyGeminiFlash(w, c.thinkingLevel),
|
|
145
164
|
"gemini-pro": (w, c) => applyGeminiPro(w, c.thinkingLevel),
|
|
146
165
|
"gemini-3.1-pro-low": (w, c) => applyGeminiPro(w, c.thinkingLevel),
|
|
147
|
-
"gemini-2.5-pro": (w, c) =>
|
|
166
|
+
"gemini-2.5-pro": (w, c) => applyGemini25Pro(w, c.thinkingLevel),
|
|
148
167
|
};
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import type { ProviderModelConfig } from "
|
|
1
|
+
import type { ChatModelConfig as ProviderModelConfig } from "../_tools.ts";
|
|
2
2
|
import { OPENAI_COMPLETIONS_COMPAT } from "./_protocols.ts";
|
|
3
3
|
import { isMaximum, type PayloadWriter, type ThinkingApplier, type ThinkingLevel } from "../_tools.ts";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* 智谱 AI(Zhipu)GLM 系列。
|
|
7
|
-
*
|
|
7
|
+
* 国内官方依据:
|
|
8
|
+
* https://docs.bigmodel.cn/cn/guide/capabilities/thinking (effort 仅 5.2+)
|
|
9
|
+
* https://docs.bigmodel.cn/cn/guide/capabilities/thinking-mode (保留式思考)
|
|
8
10
|
*/
|
|
9
11
|
export function glmModels(root: string): ProviderModelConfig[] {
|
|
10
12
|
const v1 = `${root}/v1`;
|
|
@@ -130,28 +132,29 @@ export function glmModels(root: string): ProviderModelConfig[] {
|
|
|
130
132
|
}
|
|
131
133
|
|
|
132
134
|
// GLM 思维链:`tool_stream=true` 仅在流式请求时附加;高级档位加 `clear_thinking=false`。
|
|
133
|
-
function applyGlm(writer: PayloadWriter, level: ThinkingLevel): void {
|
|
135
|
+
function applyGlm(writer: PayloadWriter, level: ThinkingLevel, effort = true, preserve = true): void {
|
|
136
|
+
if (!effort) writer.remove("reasoning_effort");
|
|
134
137
|
if (writer.get("stream") === true) writer.set("tool_stream", true);
|
|
135
138
|
if (level === "off") {
|
|
136
139
|
writer.setThinking({ type: "disabled" });
|
|
137
|
-
writer.set("reasoning_effort", "none");
|
|
140
|
+
if (effort) writer.set("reasoning_effort", "none");
|
|
138
141
|
return;
|
|
139
142
|
}
|
|
140
143
|
|
|
141
144
|
writer.setThinking({ type: "enabled" });
|
|
142
145
|
if (level === "high" || isMaximum(level)) {
|
|
143
|
-
writer.setThinking({ clear_thinking: false });
|
|
144
|
-
writer.set("reasoning_effort", isMaximum(level) ? "max" : "high");
|
|
146
|
+
if (preserve) writer.setThinking({ clear_thinking: false });
|
|
147
|
+
if (effort) writer.set("reasoning_effort", isMaximum(level) ? "max" : "high");
|
|
145
148
|
}
|
|
146
149
|
}
|
|
147
150
|
|
|
148
151
|
export const glmThinking: Record<string, ThinkingApplier> = {
|
|
149
152
|
"glm-5.2": (w, c) => applyGlm(w, c.thinkingLevel),
|
|
150
|
-
"glm-5.1": (w, c) => applyGlm(w, c.thinkingLevel),
|
|
151
|
-
"glm-5": (w, c) => applyGlm(w, c.thinkingLevel),
|
|
152
|
-
"glm-5-turbo": (w, c) => applyGlm(w, c.thinkingLevel),
|
|
153
|
-
"glm-4.7": (w, c) => applyGlm(w, c.thinkingLevel),
|
|
154
|
-
"glm-4.6": (w, c) => applyGlm(w, c.thinkingLevel),
|
|
155
|
-
"glm-4.5": (w, c) => applyGlm(w, c.thinkingLevel),
|
|
156
|
-
"glm-4.5-air": (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
|
+
"glm-4.5-air": (w, c) => applyGlm(w, c.thinkingLevel, false, false),
|
|
157
160
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ProviderModelConfig } from "
|
|
1
|
+
import type { ChatModelConfig as ProviderModelConfig } from "../_tools.ts";
|
|
2
2
|
import { OPENAI_COMPLETIONS_COMPAT } from "./_protocols.ts";
|
|
3
3
|
import { type PayloadWriter, type ThinkingApplier, type ThinkingLevel } from "../_tools.ts";
|
|
4
4
|
|
|
@@ -91,8 +91,10 @@ export function grokModels(root: string): ProviderModelConfig[] {
|
|
|
91
91
|
];
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
//
|
|
95
|
-
//
|
|
94
|
+
// 官方:https://docs.x.ai/developers/model-capabilities/text/reasoning
|
|
95
|
+
// grok-4.5 支持 low/medium/high,不支持禁用 reasoning,off 映射到 low。
|
|
96
|
+
// 4.20 / 4.3 网关别名暂保留既有映射;上述官方指南没有确认其 effort 支持,
|
|
97
|
+
// 不应将同族回归测试视为这些别名已通过端点验证。
|
|
96
98
|
function applyGrok(writer: PayloadWriter, level: ThinkingLevel): void {
|
|
97
99
|
writer.remove("thinking");
|
|
98
100
|
if (level === "off") {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import type { ProviderModelConfig } from "
|
|
1
|
+
import type { ChatModelConfig as ProviderModelConfig } from "../_tools.ts";
|
|
2
2
|
import { OPENAI_COMPLETIONS_COMPAT } from "./_protocols.ts";
|
|
3
3
|
import { applyEnabledThinking, type PayloadWriter, type ThinkingApplier, type ThinkingLevel } from "../_tools.ts";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* 月之暗面(Moonshot)Kimi 系列。
|
|
7
7
|
* 官方文档:https://platform.moonshot.cn/docs
|
|
8
|
+
* K2.7 Code 参数:https://platform.moonshot.cn/docs/api/models-overview
|
|
8
9
|
*/
|
|
9
10
|
export function kimiModels(root: string): ProviderModelConfig[] {
|
|
10
11
|
const v1 = `${root}/v1`;
|
|
@@ -33,6 +34,7 @@ export function kimiModels(root: string): ProviderModelConfig[] {
|
|
|
33
34
|
baseUrl: v1,
|
|
34
35
|
reasoning: true,
|
|
35
36
|
thinkingLevelMap: {
|
|
37
|
+
off: null,
|
|
36
38
|
low: "low",
|
|
37
39
|
medium: "medium",
|
|
38
40
|
high: "high",
|
|
@@ -51,10 +53,11 @@ export function kimiModels(root: string): ProviderModelConfig[] {
|
|
|
51
53
|
api: "openai-completions",
|
|
52
54
|
baseUrl: v1,
|
|
53
55
|
reasoning: true,
|
|
56
|
+
thinkingLevelMap: { off: null },
|
|
54
57
|
input: ["text", "image"],
|
|
55
58
|
cost: { input: 0.95, output: 4, cacheRead: 0.19, cacheWrite: 0 },
|
|
56
59
|
contextWindow: 262144,
|
|
57
|
-
//
|
|
60
|
+
// 兼容性暂存值:独立输出上限未确认,并非官方确认的输出规格。
|
|
58
61
|
maxTokens: 262144,
|
|
59
62
|
compat: OPENAI_COMPLETIONS_COMPAT,
|
|
60
63
|
},
|
|
@@ -64,10 +67,11 @@ export function kimiModels(root: string): ProviderModelConfig[] {
|
|
|
64
67
|
api: "openai-completions",
|
|
65
68
|
baseUrl: v1,
|
|
66
69
|
reasoning: true,
|
|
70
|
+
thinkingLevelMap: { off: null },
|
|
67
71
|
input: ["text", "image"],
|
|
68
72
|
cost: { input: 1.9, output: 8, cacheRead: 0.38, cacheWrite: 0 },
|
|
69
73
|
contextWindow: 262144,
|
|
70
|
-
//
|
|
74
|
+
// 兼容性暂存值:独立输出上限未确认,并非官方确认的输出规格。
|
|
71
75
|
maxTokens: 262144,
|
|
72
76
|
compat: OPENAI_COMPLETIONS_COMPAT,
|
|
73
77
|
},
|
|
@@ -80,7 +84,7 @@ export function kimiModels(root: string): ProviderModelConfig[] {
|
|
|
80
84
|
input: ["text", "image"],
|
|
81
85
|
cost: { input: 0.95, output: 4, cacheRead: 0.16, cacheWrite: 0 },
|
|
82
86
|
contextWindow: 262144,
|
|
83
|
-
//
|
|
87
|
+
// 兼容性暂存值:独立输出上限未确认,并非官方确认的输出规格。
|
|
84
88
|
maxTokens: 262144,
|
|
85
89
|
compat: OPENAI_COMPLETIONS_COMPAT,
|
|
86
90
|
},
|
|
@@ -93,7 +97,7 @@ export function kimiModels(root: string): ProviderModelConfig[] {
|
|
|
93
97
|
input: ["text", "image"],
|
|
94
98
|
cost: { input: 0.6, output: 3, cacheRead: 0.1, cacheWrite: 0 },
|
|
95
99
|
contextWindow: 262144,
|
|
96
|
-
//
|
|
100
|
+
// 兼容性暂存值:独立输出上限未确认,并非官方确认的输出规格。
|
|
97
101
|
maxTokens: 262144,
|
|
98
102
|
compat: OPENAI_COMPLETIONS_COMPAT,
|
|
99
103
|
},
|
|
@@ -103,22 +107,25 @@ export function kimiModels(root: string): ProviderModelConfig[] {
|
|
|
103
107
|
// Kimi K3 思维链:移除 `thinking` 字段,改用 `reasoning_effort` 表达深度。
|
|
104
108
|
function applyKimiK3(writer: PayloadWriter, level: ThinkingLevel): void {
|
|
105
109
|
writer.remove("thinking");
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
if (level === "minimal" || level === "low") {
|
|
110
|
+
// K3 始终思考,省略 effort 默认 max;直接或迟到的 off 请求降至 low。
|
|
111
|
+
if (level === "off" || level === "minimal" || level === "low") {
|
|
111
112
|
writer.set("reasoning_effort", "low");
|
|
112
113
|
return;
|
|
113
114
|
}
|
|
114
115
|
writer.set("reasoning_effort", level === "max" ? "max" : "high");
|
|
115
116
|
}
|
|
116
117
|
|
|
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
|
+
|
|
117
124
|
export const kimiThinking: Record<string, ThinkingApplier> = {
|
|
118
125
|
"kimi-for-coding": (w, c) => applyEnabledThinking(w, c.thinkingLevel),
|
|
119
126
|
"kimi-k3": (w, c) => applyKimiK3(w, c.thinkingLevel),
|
|
120
|
-
"kimi-k2.7-code": (w
|
|
121
|
-
"kimi-k2.7-code-highspeed": (w
|
|
127
|
+
"kimi-k2.7-code": (w) => applyKimiCode(w),
|
|
128
|
+
"kimi-k2.7-code-highspeed": (w) => applyKimiCode(w),
|
|
122
129
|
"kimi-k2.6": (w, c) => applyEnabledThinking(w, c.thinkingLevel),
|
|
123
130
|
"kimi-k2.5": (w, c) => applyEnabledThinking(w, c.thinkingLevel),
|
|
124
131
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ProviderModelConfig } from "
|
|
1
|
+
import type { ChatModelConfig as ProviderModelConfig } from "../_tools.ts";
|
|
2
2
|
import { OPENAI_COMPLETIONS_COMPAT } from "./_protocols.ts";
|
|
3
3
|
import { applyEnabledThinking, type ThinkingApplier } from "../_tools.ts";
|
|
4
4
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ProviderModelConfig } from "
|
|
1
|
+
import type { ChatModelConfig as ProviderModelConfig } from "../_tools.ts";
|
|
2
2
|
import { OPENAI_COMPLETIONS_COMPAT } from "./_protocols.ts";
|
|
3
3
|
import { applyEnabledThinking, type ThinkingApplier } from "../_tools.ts";
|
|
4
4
|
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import type { ProviderModelConfig } from "
|
|
1
|
+
import type { ChatModelConfig as ProviderModelConfig } from "../_tools.ts";
|
|
2
2
|
import { OPENAI_COMPLETIONS_COMPAT } from "./_protocols.ts";
|
|
3
3
|
import { type PayloadWriter, type ThinkingApplier, type ThinkingLevel } from "../_tools.ts";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* MiniMax 系列。
|
|
7
|
-
*
|
|
7
|
+
* 国内官方依据:
|
|
8
|
+
* https://platform.minimaxi.com/docs/api-reference/text-chat (输出上限)
|
|
9
|
+
* https://platform.minimaxi.com/docs/api-reference/text-openai-api (M2.x 强制思考)
|
|
8
10
|
*/
|
|
9
11
|
export function minimaxModels(root: string): ProviderModelConfig[] {
|
|
10
12
|
const v1 = `${root}/v1`;
|
|
@@ -23,7 +25,7 @@ export function minimaxModels(root: string): ProviderModelConfig[] {
|
|
|
23
25
|
cacheWrite: 0,
|
|
24
26
|
},
|
|
25
27
|
contextWindow: 1000000,
|
|
26
|
-
maxTokens:
|
|
28
|
+
maxTokens: 524288,
|
|
27
29
|
compat: OPENAI_COMPLETIONS_COMPAT,
|
|
28
30
|
},
|
|
29
31
|
{
|
|
@@ -32,10 +34,11 @@ export function minimaxModels(root: string): ProviderModelConfig[] {
|
|
|
32
34
|
api: "openai-completions",
|
|
33
35
|
baseUrl: v1,
|
|
34
36
|
reasoning: true,
|
|
37
|
+
thinkingLevelMap: { off: null },
|
|
35
38
|
input: ["text"],
|
|
36
39
|
cost: { input: 0.3, output: 1.2, cacheRead: 0.06, cacheWrite: 0.375 },
|
|
37
40
|
contextWindow: 204800,
|
|
38
|
-
//
|
|
41
|
+
// 官方 max_completion_tokens 上限,并非上下文估算。
|
|
39
42
|
maxTokens: 204800,
|
|
40
43
|
compat: OPENAI_COMPLETIONS_COMPAT,
|
|
41
44
|
},
|
|
@@ -45,10 +48,11 @@ export function minimaxModels(root: string): ProviderModelConfig[] {
|
|
|
45
48
|
api: "openai-completions",
|
|
46
49
|
baseUrl: v1,
|
|
47
50
|
reasoning: true,
|
|
51
|
+
thinkingLevelMap: { off: null },
|
|
48
52
|
input: ["text"],
|
|
49
53
|
cost: { input: 0.3, output: 1.2, cacheRead: 0.03, cacheWrite: 0.375 },
|
|
50
54
|
contextWindow: 204800,
|
|
51
|
-
//
|
|
55
|
+
// 官方 max_completion_tokens 上限,并非上下文估算。
|
|
52
56
|
maxTokens: 204800,
|
|
53
57
|
compat: OPENAI_COMPLETIONS_COMPAT,
|
|
54
58
|
},
|
|
@@ -58,10 +62,11 @@ export function minimaxModels(root: string): ProviderModelConfig[] {
|
|
|
58
62
|
api: "openai-completions",
|
|
59
63
|
baseUrl: v1,
|
|
60
64
|
reasoning: true,
|
|
65
|
+
thinkingLevelMap: { off: null },
|
|
61
66
|
input: ["text"],
|
|
62
67
|
cost: { input: 0.3, output: 1.2, cacheRead: 0.03, cacheWrite: 0.375 },
|
|
63
68
|
contextWindow: 204800,
|
|
64
|
-
//
|
|
69
|
+
// 官方 max_completion_tokens 上限,并非上下文估算。
|
|
65
70
|
maxTokens: 204800,
|
|
66
71
|
compat: OPENAI_COMPLETIONS_COMPAT,
|
|
67
72
|
},
|
|
@@ -69,7 +74,7 @@ export function minimaxModels(root: string): ProviderModelConfig[] {
|
|
|
69
74
|
}
|
|
70
75
|
|
|
71
76
|
// MiniMax 思维链:`reasoning_split=true`,档位映射 disabled/adaptive。
|
|
72
|
-
// M2.x
|
|
77
|
+
// 国内 OpenAI SDK 文档明确区分:M3 可关闭;M2.x disabled 被接受但不生效。
|
|
73
78
|
function applyMiniMax(writer: PayloadWriter, level: ThinkingLevel): void {
|
|
74
79
|
writer.remove("reasoning_effort");
|
|
75
80
|
writer.set("reasoning_split", true);
|
|
@@ -78,7 +83,7 @@ function applyMiniMax(writer: PayloadWriter, level: ThinkingLevel): void {
|
|
|
78
83
|
|
|
79
84
|
export const minimaxThinking = {
|
|
80
85
|
"MiniMax-M3": (w, c) => applyMiniMax(w, c.thinkingLevel),
|
|
81
|
-
"MiniMax-M2.7": (w
|
|
82
|
-
"MiniMax-M2.5": (w
|
|
83
|
-
"MiniMax-M2.1": (w
|
|
86
|
+
"MiniMax-M2.7": (w) => applyMiniMax(w, "high"),
|
|
87
|
+
"MiniMax-M2.5": (w) => applyMiniMax(w, "high"),
|
|
88
|
+
"MiniMax-M2.1": (w) => applyMiniMax(w, "high"),
|
|
84
89
|
} satisfies Record<string, ThinkingApplier>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ProviderModelConfig } from "
|
|
1
|
+
import type { ChatModelConfig as ProviderModelConfig } from "../_tools.ts";
|
|
2
2
|
import { OPENAI_COMPLETIONS_COMPAT } from "./_protocols.ts";
|
|
3
3
|
import { isAtLeastHigh, type PayloadWriter, type ThinkingApplier, type ThinkingLevel } from "../_tools.ts";
|
|
4
4
|
|
|
@@ -92,10 +92,10 @@ function applyGrokSearch(writer: PayloadWriter): void {
|
|
|
92
92
|
|
|
93
93
|
/**
|
|
94
94
|
* Append-only built-in search injection for models with native search.
|
|
95
|
-
* Non-plain payloads
|
|
95
|
+
* Non-plain payloads and unsupported models are returned
|
|
96
96
|
* unchanged. Existing function tools, `tool_choice`, and `include` are
|
|
97
|
-
* preserved.
|
|
98
|
-
*
|
|
97
|
+
* preserved. Sources are not requested: this conservative policy originated
|
|
98
|
+
* with Pi 0.82.0; source rendering on newer hosts needs separate validation.
|
|
99
99
|
*/
|
|
100
100
|
export function applyBuiltinSearchTool<T>(
|
|
101
101
|
payload: T,
|
|
@@ -103,7 +103,7 @@ export function applyBuiltinSearchTool<T>(
|
|
|
103
103
|
api: string,
|
|
104
104
|
mode: WebSearchMode,
|
|
105
105
|
): T | Payload {
|
|
106
|
-
if (!isPlainObject(payload)
|
|
106
|
+
if (!isPlainObject(payload)) return payload;
|
|
107
107
|
const writer = new PayloadWriter(payload);
|
|
108
108
|
const support = builtinSearchSupport(modelId, api);
|
|
109
109
|
|
package/extensions/status.ts
CHANGED
|
@@ -82,8 +82,7 @@ export function searchLabel(
|
|
|
82
82
|
support: "gpt" | "grok" | undefined,
|
|
83
83
|
): string {
|
|
84
84
|
if (support === undefined) return "⚪ 内置联网:不支持";
|
|
85
|
-
|
|
86
|
-
// Grok 的 cached/live 均注入 mode: "on",不能声称是缓存查询。
|
|
85
|
+
// Grok 固定实时,不受 GPT 的 cached/live 会话模式影响。
|
|
87
86
|
if (support === "grok" || mode === "live") return "🟢 内置联网:实时";
|
|
88
87
|
return "🟡 内置联网:缓存";
|
|
89
88
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-tsgw",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"description": "Pi extension for the TOSSP AIH gateway: per-vendor model catalog and thinking operations for openai-completions, openai-responses, anthropic-messages, and google-generative-ai wire protocols.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -21,14 +21,14 @@
|
|
|
21
21
|
]
|
|
22
22
|
},
|
|
23
23
|
"scripts": {
|
|
24
|
-
"test": "tsc -p tsconfig.test.json && node dist/extensions/index.test.js && node dist/extensions/status.test.js && node dist/extensions/status-integration.test.js && node dist/extensions/models/gateway-catalog-metadata.test.js && node dist/extensions/models/operations.test.js && node dist/extensions/models/catalog.test.js && node dist/extensions/models/web-search.test.js && node dist/extensions/models/gateway-catalog.test.js"
|
|
24
|
+
"test": "tsc -p tsconfig.test.json && node dist/extensions/index.test.js && node dist/extensions/status.test.js && node dist/extensions/status-integration.test.js && node dist/extensions/models/gateway-catalog-metadata.test.js && node dist/extensions/models/operations.test.js && node dist/extensions/models/catalog.test.js && node dist/extensions/models/web-search.test.js && node dist/extensions/models/gateway-catalog.test.js && node dist/extensions/models/gateway-catalog-isolation.test.js && node dist/extensions/models/vendor-strategies.test.js && node dist/extensions/host-integration.test.js"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"@earendil-works/pi-coding-agent": ">=0.82.0",
|
|
28
28
|
"typebox": "*"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@earendil-works/pi-coding-agent": "^
|
|
31
|
+
"@earendil-works/pi-coding-agent": "^1.1.0",
|
|
32
32
|
"typebox": "^1.3.11",
|
|
33
33
|
"typescript": "^7.0.2"
|
|
34
34
|
}
|