pi-model-manager 0.4.8 → 0.4.9
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.en.md +1 -0
- package/README.md +1 -0
- package/package.json +1 -1
- package/presets/builtin-client-headers.ts +3 -3
- package/presets/thinking.ts +22 -5
- package/provider-transport.ts +42 -4
- package/state-document.ts +2 -1
- package/state-store.ts +1 -1
package/README.en.md
CHANGED
|
@@ -132,6 +132,7 @@ Ctrl+S 保存并启用模型;不切换当前会话模型
|
|
|
132
132
|
- Fetch model IDs from compatible upstream APIs or enter them manually.
|
|
133
133
|
- Configure context window, maximum output, vision support, and reasoning support.
|
|
134
134
|
- Choose Anthropic Adaptive Thinking or Legacy Thinking.
|
|
135
|
+
- New level-based Gemini models expose `minimal / low / medium / high / xhigh / max` by default and send the matching uppercase value; support is determined by the upstream service. Budget-based Gemini models retain native levels and token budgets. Existing explicit level mappings and disabled levels are not automatically rewritten.
|
|
135
136
|
- Select Standard, Fast (`priority`), or Ultrafast (`ultrafast`) service tiers per OpenAI Responses model.
|
|
136
137
|
- Route each provider directly or through its own HTTP(S) proxy.
|
|
137
138
|
- Use recommended, disabled, Claude Code, Codex, or custom client-header profiles.
|
package/README.md
CHANGED
|
@@ -132,6 +132,7 @@ Ctrl+S 保存并启用模型;不切换当前会话模型
|
|
|
132
132
|
- 从兼容上游拉取模型 ID,也可手动填写模型。
|
|
133
133
|
- 配置上下文窗口、最大输出、视觉支持和 Thinking。
|
|
134
134
|
- 支持 Anthropic Adaptive Thinking 与 Legacy Thinking。
|
|
135
|
+
- 等级制 Gemini 的新模型默认开放 `minimal / low / medium / high / xhigh / max`,按同名值发送(按协议转为大写),是否支持由上游判断;预算制 Gemini 保留原生档位与 token 预算规则。已有显式档位映射和禁用配置不会自动重写。
|
|
135
136
|
- 为 OpenAI Responses 模型选择标准、Fast(`priority`)或 Ultrafast(`ultrafast`)速度档位。
|
|
136
137
|
- 为每个接入单独配置直连或 HTTP(S) 代理。
|
|
137
138
|
- 提供自动推荐、禁用、Claude Code、Codex 和自定义请求头模式。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-model-manager",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.9",
|
|
4
4
|
"description": "A TUI model and provider manager for Pi with native models.json persistence, request-header profiles, proxy routing, and protocol compatibility.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
export const CLAUDE_CODE_CLIENT_HEADERS: Record<string, string> = {
|
|
4
4
|
"anthropic-dangerous-direct-browser-access": "true",
|
|
5
5
|
"anthropic-version": "2023-06-01",
|
|
6
|
-
"user-agent": "claude-cli/2.1.
|
|
6
|
+
"user-agent": "claude-cli/2.1.332 (external, sdk-cli)",
|
|
7
7
|
"x-app": "cli",
|
|
8
8
|
"x-stainless-arch": "x64",
|
|
9
9
|
"x-stainless-lang": "js",
|
|
@@ -17,6 +17,6 @@ export const CLAUDE_CODE_CLIENT_HEADERS: Record<string, string> = {
|
|
|
17
17
|
|
|
18
18
|
export const CODEX_CLI_CLIENT_HEADERS: Record<string, string> = {
|
|
19
19
|
"originator": "codex_cli_rs",
|
|
20
|
-
"user-agent": "codex_cli_rs/0.
|
|
21
|
-
"version": "0.
|
|
20
|
+
"user-agent": "codex_cli_rs/0.172.0 (Windows 10.0.26100; x86_64) unknown",
|
|
21
|
+
"version": "0.172.0",
|
|
22
22
|
};
|
package/presets/thinking.ts
CHANGED
|
@@ -16,8 +16,8 @@ const OPENAI_THINKING_LEVEL_MAP: ThinkingLevelMap = {
|
|
|
16
16
|
max: "max",
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
//
|
|
20
|
-
const
|
|
19
|
+
// 预算制模型保留原生档位与 token 预算规则。
|
|
20
|
+
const GOOGLE_BUDGET_THINKING_LEVEL_MAP: ThinkingLevelMap = {
|
|
21
21
|
minimal: "minimal",
|
|
22
22
|
low: "low",
|
|
23
23
|
medium: "medium",
|
|
@@ -26,6 +26,17 @@ const GOOGLE_GENERATIVE_AI_THINKING_LEVEL_MAP: ThinkingLevelMap = {
|
|
|
26
26
|
max: null,
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
+
export function usesGoogleThinkingLevel(modelId: string): boolean {
|
|
30
|
+
const id = modelId.toLowerCase();
|
|
31
|
+
const major = Number(id.match(/gemini(?:-live)?-(\d+)/)?.[1] ?? 0);
|
|
32
|
+
// [喵喵喵]: 与 Pi 的 Google wire-format 分类一致;只区分等级制/预算制,不判断各模型支持哪些档位。
|
|
33
|
+
return /gemini-3(?:\.\d+)?-(?:pro|flash)/.test(id)
|
|
34
|
+
|| major >= 4
|
|
35
|
+
|| id === "gemini-flash-latest"
|
|
36
|
+
|| id === "gemini-flash-lite-latest"
|
|
37
|
+
|| /gemma-?4/.test(id);
|
|
38
|
+
}
|
|
39
|
+
|
|
29
40
|
function isLegacyShiftedMaxLadder(map: ThinkingLevelMap): boolean {
|
|
30
41
|
return map.minimal === "low"
|
|
31
42
|
&& map.low === "medium"
|
|
@@ -35,9 +46,14 @@ function isLegacyShiftedMaxLadder(map: ThinkingLevelMap): boolean {
|
|
|
35
46
|
&& map.max === undefined;
|
|
36
47
|
}
|
|
37
48
|
|
|
38
|
-
function buildThinkingLevelMap(api: ApiKind, reasoning: boolean): ThinkingLevelMap | undefined {
|
|
49
|
+
function buildThinkingLevelMap(api: ApiKind, reasoning: boolean, modelId: string): ThinkingLevelMap | undefined {
|
|
39
50
|
if (!reasoning) return undefined;
|
|
40
|
-
if (api === "google-generative-ai")
|
|
51
|
+
if (api === "google-generative-ai") {
|
|
52
|
+
return {
|
|
53
|
+
...GOOGLE_BUDGET_THINKING_LEVEL_MAP,
|
|
54
|
+
...(usesGoogleThinkingLevel(modelId) ? EXTENDED_THINKING_LEVEL_MAP : {}),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
41
57
|
if (api === "openai-completions" || api === "openai-responses") return { ...OPENAI_THINKING_LEVEL_MAP };
|
|
42
58
|
return { ...EXTENDED_THINKING_LEVEL_MAP };
|
|
43
59
|
}
|
|
@@ -54,9 +70,10 @@ export function normalizeThinkingLevelMap(
|
|
|
54
70
|
api: ApiKind,
|
|
55
71
|
reasoning: boolean,
|
|
56
72
|
storedMap: ThinkingLevelMap | undefined,
|
|
73
|
+
modelId: string,
|
|
57
74
|
): ThinkingLevelMap | undefined {
|
|
58
75
|
if (!reasoning) return undefined;
|
|
59
|
-
const defaultMap = buildThinkingLevelMap(api, true);
|
|
76
|
+
const defaultMap = buildThinkingLevelMap(api, true, modelId);
|
|
60
77
|
if (storedMap && isLegacyShiftedMaxLadder(storedMap)) return defaultMap;
|
|
61
78
|
return mergeThinkingLevelMap(defaultMap, storedMap);
|
|
62
79
|
}
|
package/provider-transport.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
// 在 Pi 已构造请求后选择传输路线;协议判断始终使用真实网关地址。
|
|
2
2
|
|
|
3
3
|
import { lazyStream, type Provider } from "@earendil-works/pi-ai";
|
|
4
|
+
import { isObjectRecord } from "./common.ts";
|
|
4
5
|
import { getClaudeCodeSessionId } from "./claude-code-compat.ts";
|
|
5
6
|
import { applyCodexRequestHeaders } from "./codex-compat.ts";
|
|
6
7
|
import { mergeModelRequestHeaders, resolveClientHeaderProfile } from "./presets/client-headers.ts";
|
|
8
|
+
import { usesGoogleThinkingLevel } from "./presets/thinking.ts";
|
|
7
9
|
import { t } from "./i18n.ts";
|
|
8
10
|
import { getProviderHttpProxyUrl, openTemporaryLocalProxyRoute } from "./local-proxy-service.ts";
|
|
9
11
|
import { appendUrlPath, resolveRuntimeBaseUrl, validateRequestBaseUrl } from "./runtime-base-url.ts";
|
|
@@ -101,15 +103,51 @@ export function createProviderTransport(native: Provider, provider: StoredProvid
|
|
|
101
103
|
}));
|
|
102
104
|
const proxyUrl = provider.httpProxyEnabled ? getProviderHttpProxyUrl(provider) : undefined;
|
|
103
105
|
|
|
104
|
-
const wrap = (stream: Provider["streamSimple"]): Provider["streamSimple"] => (model, context, options) => lazyStream(model, async () => {
|
|
106
|
+
const wrap = (stream: Provider["streamSimple"], simple: boolean): Provider["streamSimple"] => (model, context, options) => lazyStream(model, async () => {
|
|
105
107
|
const endpoint = endpoints.get(model.id);
|
|
106
108
|
if (!endpoint || endpoint.api !== model.api) throw new Error(t("请求模型不属于当前接入配置:{modelId}", { modelId: model.id }));
|
|
107
109
|
validateRequestBaseUrl(endpoint.baseUrl);
|
|
108
110
|
// [喵喵喵]: models.json 已保存完整模型头,由宿主在 transformHeaders 前解析;发送层不能再次合并配置而复活被删除的头。
|
|
109
111
|
options = { ...options };
|
|
110
112
|
// [喵喵喵]: models.json 会叠加在动态 provider 之上;还原用户侧 API 根地址,不能让原生持久化形式参与路径拼接。
|
|
111
|
-
|
|
113
|
+
let upstreamModel = { ...model, baseUrl: endpoint.baseUrl };
|
|
112
114
|
if (model.api === "google-generative-ai") {
|
|
115
|
+
if (simple && model.reasoning && options.reasoning && usesGoogleThinkingLevel(model.id)
|
|
116
|
+
&& model.thinkingLevelMap?.[options.reasoning] !== null) {
|
|
117
|
+
const level = options.reasoning;
|
|
118
|
+
const mappedLevel = model.thinkingLevelMap?.[level] ?? level;
|
|
119
|
+
const originalOptions = options;
|
|
120
|
+
const restoreModel = (requestModel: typeof model) => ({
|
|
121
|
+
...requestModel,
|
|
122
|
+
reasoning: model.reasoning,
|
|
123
|
+
samplingParamsByThinkingLevel: model.samplingParamsByThinkingLevel,
|
|
124
|
+
});
|
|
125
|
+
const { reasoning: _reasoning, ...nativeOptions } = options;
|
|
126
|
+
// [喵喵喵]: 禁用原生档位转换而非借用低档位;通用限额仍由 streamSimple 计算,采样参数按真实选择预先合并。
|
|
127
|
+
upstreamModel = { ...upstreamModel, reasoning: false, samplingParamsByThinkingLevel: undefined };
|
|
128
|
+
options = {
|
|
129
|
+
...nativeOptions,
|
|
130
|
+
samplingParams: {
|
|
131
|
+
...model.samplingParams,
|
|
132
|
+
...model.samplingParamsByThinkingLevel?.[level],
|
|
133
|
+
...options.samplingParams,
|
|
134
|
+
},
|
|
135
|
+
async onPayload(payload, requestModel) {
|
|
136
|
+
if (!isObjectRecord(payload) || !isObjectRecord(payload.config)) {
|
|
137
|
+
throw new Error("Google request payload is missing its config object");
|
|
138
|
+
}
|
|
139
|
+
payload.config.thinkingConfig = { includeThoughts: true, thinkingLevel: mappedLevel.toUpperCase() };
|
|
140
|
+
// [喵喵喵]: 先提供最终档位,再调用原有钩子;钩子的替换、修改和拒绝都保留。
|
|
141
|
+
return originalOptions.onPayload?.(payload, restoreModel(requestModel));
|
|
142
|
+
},
|
|
143
|
+
onResponse: originalOptions.onResponse
|
|
144
|
+
? (response, requestModel) => originalOptions.onResponse!(response, restoreModel(requestModel))
|
|
145
|
+
: undefined,
|
|
146
|
+
onProviderStreamEvent: originalOptions.onProviderStreamEvent
|
|
147
|
+
? (event, requestModel) => originalOptions.onProviderStreamEvent!(event, restoreModel(requestModel))
|
|
148
|
+
: undefined,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
113
151
|
// [喵喵喵]: Google 适配器先按精确键拼入默认 User-Agent,再构造 Headers;使用该拼写才能覆盖而不是合并成两个值。
|
|
114
152
|
if (options.headers?.["user-agent"] !== undefined) {
|
|
115
153
|
const { "user-agent": userAgent, ...headers } = options.headers;
|
|
@@ -203,7 +241,7 @@ export function createProviderTransport(native: Provider, provider: StoredProvid
|
|
|
203
241
|
|
|
204
242
|
return {
|
|
205
243
|
...native,
|
|
206
|
-
stream: wrap(native.stream.bind(native)) as Provider["stream"],
|
|
207
|
-
streamSimple: wrap(native.streamSimple.bind(native)),
|
|
244
|
+
stream: wrap(native.stream.bind(native), false) as Provider["stream"],
|
|
245
|
+
streamSimple: wrap(native.streamSimple.bind(native), true),
|
|
208
246
|
};
|
|
209
247
|
}
|
package/state-document.ts
CHANGED
|
@@ -348,6 +348,7 @@ function keepModelFieldsSupportedByApi(model: StoredModel, providerApi: ApiKind,
|
|
|
348
348
|
effectiveApi,
|
|
349
349
|
next.reasoning,
|
|
350
350
|
providerApiChanged && !normalized.api ? undefined : next.thinkingLevelMap,
|
|
351
|
+
next.id,
|
|
351
352
|
);
|
|
352
353
|
if (thinkingLevelMap) next.thinkingLevelMap = thinkingLevelMap;
|
|
353
354
|
else delete next.thinkingLevelMap;
|
|
@@ -427,7 +428,7 @@ export function buildModelFromDraft(
|
|
|
427
428
|
const compat: CompatSettings = cloneJson(existing?.compat) ?? {};
|
|
428
429
|
const effectiveApi = isApiKind(existing?.api) ? existing.api : draft.api;
|
|
429
430
|
const storedThinkingLevelMap = cloneJson(existing?.thinkingLevelMap);
|
|
430
|
-
const thinkingLevelMap = normalizeThinkingLevelMap(effectiveApi, reasoning, storedThinkingLevelMap);
|
|
431
|
+
const thinkingLevelMap = normalizeThinkingLevelMap(effectiveApi, reasoning, storedThinkingLevelMap, modelId);
|
|
431
432
|
|
|
432
433
|
const next: StoredModel = {
|
|
433
434
|
id: modelId,
|
package/state-store.ts
CHANGED
|
@@ -164,7 +164,7 @@ function buildStoredModelFromModelsJson(
|
|
|
164
164
|
if (nativeHeaders) stored.headers = nativeHeaders;
|
|
165
165
|
if (model.name) stored.name = model.name;
|
|
166
166
|
const storedThinkingLevelMap = model.thinkingLevelMap ? cloneJson(model.thinkingLevelMap) as ThinkingLevelMap : undefined;
|
|
167
|
-
const thinkingLevelMap = normalizeThinkingLevelMap(effectiveApi, stored.reasoning, storedThinkingLevelMap);
|
|
167
|
+
const thinkingLevelMap = normalizeThinkingLevelMap(effectiveApi, stored.reasoning, storedThinkingLevelMap, stored.id);
|
|
168
168
|
if (thinkingLevelMap) stored.thinkingLevelMap = thinkingLevelMap;
|
|
169
169
|
if (modelCompat) stored.compat = modelCompat;
|
|
170
170
|
if (effectiveApi === "openai-responses" && modelMetadata?.openAIServiceTier) {
|