pi-model-manager 0.3.3 → 0.3.4
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/i18n.ts +3 -6
- package/package.json +1 -1
- package/presets/providers.ts +3 -3
- package/state-document.ts +9 -11
- package/tui/editor-provider.ts +26 -29
- package/types.ts +3 -3
package/i18n.ts
CHANGED
|
@@ -76,15 +76,12 @@ const ENGLISH_MESSAGES = {
|
|
|
76
76
|
"代理地址": "Proxy URL",
|
|
77
77
|
"认证头": "Auth header",
|
|
78
78
|
"协议兼容": "Protocol compatibility",
|
|
79
|
-
"
|
|
80
|
-
"标准 · developer": "Standard · developer",
|
|
79
|
+
"标准 · Pi 默认": "Standard · Pi default",
|
|
81
80
|
"兼容 · system": "Compatible · system",
|
|
82
81
|
"选择协议兼容": "Select protocol compatibility",
|
|
83
|
-
"
|
|
84
|
-
"标准 — 对 reasoning 模型使用 developer role,适合标准 OpenAI 端点": "Standard — use the developer role for reasoning models on conformant OpenAI endpoints",
|
|
82
|
+
"标准 — 保持 Pi 默认兼容判断": "Standard — keep Pi's default compatibility detection",
|
|
85
83
|
"兼容 — 强制 system role,适合忽略 developer 的中转": "Compatible — force the system role for relays that ignore developer",
|
|
86
|
-
"
|
|
87
|
-
"标准模式:reasoning 模型的系统提示词使用 developer role。": "Standard mode: reasoning-model system prompts use the developer role.",
|
|
84
|
+
"标准模式:保持 Pi 默认兼容判断。": "Standard mode: keep Pi's default compatibility detection.",
|
|
88
85
|
"兼容模式:系统提示词强制使用 system role,适合忽略 developer 的中转。": "Compatibility mode: the system prompt always uses the system role for relays that ignore developer.",
|
|
89
86
|
"接入 ID 必填,且不能与已有或 pi 内置接入重复": "Provider ID is required and must not duplicate an existing or built-in Pi provider",
|
|
90
87
|
"Ctrl+S 保存并同步 models.json;不切换当前会话模型": "Ctrl+S saves and syncs models.json without switching the current session model",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-model-manager",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
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
|
"main": "./index.ts",
|
package/presets/providers.ts
CHANGED
|
@@ -99,9 +99,9 @@ export function switchProviderDraftApiPreset(draft: ProviderDraft, nextApi: ApiK
|
|
|
99
99
|
const replaceBaseUrl = stillUsesPresetUrl(draft.baseUrl, previousPreset.baseUrl);
|
|
100
100
|
const replaceApiKey = draft.apiKey === previousPreset.apiKey;
|
|
101
101
|
draft.api = nextApi;
|
|
102
|
-
// [喵喵喵]: 协议切换回来时保留用户原先的选择;首次切入 Chat
|
|
103
|
-
if (nextApi === "openai-completions" && draft.
|
|
104
|
-
draft.
|
|
102
|
+
// [喵喵喵]: 协议切换回来时保留用户原先的选择;首次切入 Chat 才补标准模式。
|
|
103
|
+
if (nextApi === "openai-completions" && draft.openAIChatCompatibilityMode === undefined) {
|
|
104
|
+
draft.openAIChatCompatibilityMode = "standard";
|
|
105
105
|
}
|
|
106
106
|
// [喵喵喵]: 版本路径规则随协议而变(OpenAI 要 /v1、Anthropic 不要),
|
|
107
107
|
// 保留的自定义地址必须按新协议重新归一化,否则切完协议就指向错误端点。
|
package/state-document.ts
CHANGED
|
@@ -23,7 +23,7 @@ import { resolveRuntimeBaseUrl } from "./runtime-base-url.ts";
|
|
|
23
23
|
import type {
|
|
24
24
|
ApiKind,
|
|
25
25
|
CompatSettings,
|
|
26
|
-
|
|
26
|
+
OpenAIChatCompatibilityMode,
|
|
27
27
|
ModelDraft,
|
|
28
28
|
ProviderDraft,
|
|
29
29
|
RequestHeaderProfileDraft,
|
|
@@ -45,10 +45,8 @@ function isApiKind(value: unknown): value is ApiKind {
|
|
|
45
45
|
return typeof value === "string" && API_KINDS.includes(value as ApiKind);
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
function
|
|
49
|
-
|
|
50
|
-
if (compat?.supportsDeveloperRole === false) return "system";
|
|
51
|
-
return "auto";
|
|
48
|
+
function getOpenAIChatCompatibilityMode(compat: CompatSettings | undefined): OpenAIChatCompatibilityMode {
|
|
49
|
+
return compat?.supportsDeveloperRole === false ? "compatible" : "standard";
|
|
52
50
|
}
|
|
53
51
|
|
|
54
52
|
export function getModelFullId(providerId: string, modelId: string): string {
|
|
@@ -84,7 +82,7 @@ export function createProviderDraft(api: ApiKind = "openai-responses"): Provider
|
|
|
84
82
|
providerId: "",
|
|
85
83
|
providerName: preset.defaultProviderName,
|
|
86
84
|
api,
|
|
87
|
-
|
|
85
|
+
openAIChatCompatibilityMode: "standard",
|
|
88
86
|
baseUrl: preset.baseUrl,
|
|
89
87
|
apiKey: preset.apiKey,
|
|
90
88
|
authHeader: preset.authHeader,
|
|
@@ -103,7 +101,7 @@ export function createProviderDraftFromStored(providerId: string, stored: Stored
|
|
|
103
101
|
providerId,
|
|
104
102
|
providerName: stored.name ?? (providerId.replace(/^custom-/, "") || preset.defaultProviderName),
|
|
105
103
|
api,
|
|
106
|
-
|
|
104
|
+
openAIChatCompatibilityMode: getOpenAIChatCompatibilityMode(stored.compat),
|
|
107
105
|
baseUrl: stored.baseUrl ?? preset.baseUrl,
|
|
108
106
|
apiKey: stored.apiKey ?? "",
|
|
109
107
|
authHeader: stored.authHeader ?? preset.authHeader,
|
|
@@ -287,7 +285,7 @@ export function getProviderChangeWarnings(
|
|
|
287
285
|
if ((current.api ?? "") !== draft.api) changes.push(t("API 协议"));
|
|
288
286
|
if ((current.authHeader ?? false) !== draft.authHeader) changes.push(t("认证头"));
|
|
289
287
|
if (draft.api === "openai-completions"
|
|
290
|
-
&&
|
|
288
|
+
&& getOpenAIChatCompatibilityMode(current.compat) !== (draft.openAIChatCompatibilityMode ?? "standard")) {
|
|
291
289
|
changes.push(t("协议兼容"));
|
|
292
290
|
}
|
|
293
291
|
if ((current.clientHeaderProfile ?? "recommended") !== draft.clientHeaderProfile
|
|
@@ -365,10 +363,10 @@ function buildProviderFromDraft(
|
|
|
365
363
|
} else {
|
|
366
364
|
delete next.customClientHeaders;
|
|
367
365
|
}
|
|
368
|
-
if (draft.api === "openai-completions" && draft.
|
|
366
|
+
if (draft.api === "openai-completions" && draft.openAIChatCompatibilityMode !== undefined) {
|
|
369
367
|
const compat: CompatSettings = cloneJson(next.compat) ?? {};
|
|
370
|
-
if (draft.
|
|
371
|
-
else compat.supportsDeveloperRole =
|
|
368
|
+
if (draft.openAIChatCompatibilityMode === "standard") delete compat.supportsDeveloperRole;
|
|
369
|
+
else compat.supportsDeveloperRole = false;
|
|
372
370
|
if (Object.keys(compat).length > 0) next.compat = compat;
|
|
373
371
|
else delete next.compat;
|
|
374
372
|
}
|
package/tui/editor-provider.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { t } from "../i18n.ts";
|
|
|
9
9
|
import { switchProviderDraftApiPreset } from "../presets/providers.ts";
|
|
10
10
|
import { redactUrlForDisplay } from "../sensitive-redaction.ts";
|
|
11
11
|
import { resolveRuntimeBaseUrl } from "../runtime-base-url.ts";
|
|
12
|
-
import { DEFAULT_PROVIDER_HTTP_PROXY_URL, type
|
|
12
|
+
import { DEFAULT_PROVIDER_HTTP_PROXY_URL, type OpenAIChatCompatibilityMode } from "../types.ts";
|
|
13
13
|
import { showOptionPicker, showPersistentFormMenu, padLabel, type HorizontalDirection, type MenuCursor } from "./persistent-menu.ts";
|
|
14
14
|
import {
|
|
15
15
|
describeProfile,
|
|
@@ -28,31 +28,29 @@ interface FieldRow {
|
|
|
28
28
|
adjustable?: boolean;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
const
|
|
31
|
+
const OPENAI_CHAT_COMPATIBILITY_MODE_ORDER: readonly OpenAIChatCompatibilityMode[] = ["standard", "compatible"];
|
|
32
32
|
|
|
33
|
-
function
|
|
34
|
-
return draft.
|
|
33
|
+
function getOpenAIChatCompatibilityMode(draft: ProviderDraft): OpenAIChatCompatibilityMode {
|
|
34
|
+
return draft.openAIChatCompatibilityMode ?? "standard";
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
function
|
|
38
|
-
if (
|
|
39
|
-
|
|
40
|
-
return t("自动 · Pi 默认");
|
|
37
|
+
function describeOpenAIChatCompatibilityMode(mode: OpenAIChatCompatibilityMode): string {
|
|
38
|
+
if (mode === "compatible") return t("兼容 · system");
|
|
39
|
+
return t("标准 · Pi 默认");
|
|
41
40
|
}
|
|
42
41
|
|
|
43
|
-
function
|
|
44
|
-
if (
|
|
45
|
-
|
|
46
|
-
return t("自动模式:由 Pi 判断系统提示词使用 developer 或 system role。");
|
|
42
|
+
function getOpenAIChatCompatibilityModeHint(mode: OpenAIChatCompatibilityMode): string {
|
|
43
|
+
if (mode === "compatible") return t("兼容模式:系统提示词强制使用 system role,适合忽略 developer 的中转。");
|
|
44
|
+
return t("标准模式:保持 Pi 默认兼容判断。");
|
|
47
45
|
}
|
|
48
46
|
|
|
49
|
-
function
|
|
50
|
-
|
|
47
|
+
function cycleOpenAIChatCompatibilityMode(
|
|
48
|
+
mode: OpenAIChatCompatibilityMode,
|
|
51
49
|
direction: HorizontalDirection,
|
|
52
|
-
):
|
|
53
|
-
const index =
|
|
50
|
+
): OpenAIChatCompatibilityMode {
|
|
51
|
+
const index = OPENAI_CHAT_COMPATIBILITY_MODE_ORDER.indexOf(mode);
|
|
54
52
|
const offset = direction === "right" ? 1 : -1;
|
|
55
|
-
return
|
|
53
|
+
return OPENAI_CHAT_COMPATIBILITY_MODE_ORDER[(index + offset + OPENAI_CHAT_COMPATIBILITY_MODE_ORDER.length) % OPENAI_CHAT_COMPATIBILITY_MODE_ORDER.length]!;
|
|
56
54
|
}
|
|
57
55
|
|
|
58
56
|
function buildRows(
|
|
@@ -73,9 +71,9 @@ function buildRows(
|
|
|
73
71
|
];
|
|
74
72
|
if (draft.api === "openai-completions") {
|
|
75
73
|
rows.push({
|
|
76
|
-
id: "
|
|
74
|
+
id: "openAIChatCompatibilityMode",
|
|
77
75
|
label: t("协议兼容"),
|
|
78
|
-
value:
|
|
76
|
+
value: describeOpenAIChatCompatibilityMode(getOpenAIChatCompatibilityMode(draft)),
|
|
79
77
|
adjustable: true,
|
|
80
78
|
});
|
|
81
79
|
}
|
|
@@ -91,10 +89,10 @@ function buildRows(
|
|
|
91
89
|
|
|
92
90
|
|
|
93
91
|
|
|
94
|
-
//
|
|
92
|
+
// 二值开关的两个方向都取反。
|
|
95
93
|
function applyHorizontalToggle(draft: ProviderDraft, fieldId: string, direction: HorizontalDirection): boolean {
|
|
96
|
-
if (fieldId === "
|
|
97
|
-
draft.
|
|
94
|
+
if (fieldId === "openAIChatCompatibilityMode") {
|
|
95
|
+
draft.openAIChatCompatibilityMode = cycleOpenAIChatCompatibilityMode(getOpenAIChatCompatibilityMode(draft), direction);
|
|
98
96
|
return true;
|
|
99
97
|
}
|
|
100
98
|
if (fieldId !== "httpProxyEnabled") return false;
|
|
@@ -142,18 +140,17 @@ async function editField(
|
|
|
142
140
|
if (choice) switchProviderDraftApiPreset(draft, choice.id);
|
|
143
141
|
return;
|
|
144
142
|
}
|
|
145
|
-
if (fieldId === "
|
|
143
|
+
if (fieldId === "openAIChatCompatibilityMode") {
|
|
146
144
|
const choice = await showOptionPicker(
|
|
147
145
|
ctx,
|
|
148
146
|
t("选择协议兼容"),
|
|
149
147
|
[
|
|
150
|
-
{ id: "
|
|
151
|
-
{ id: "
|
|
152
|
-
{ id: "system", label: t("兼容 — 强制 system role,适合忽略 developer 的中转") },
|
|
148
|
+
{ id: "standard", label: t("标准 — 保持 Pi 默认兼容判断") },
|
|
149
|
+
{ id: "compatible", label: t("兼容 — 强制 system role,适合忽略 developer 的中转") },
|
|
153
150
|
],
|
|
154
|
-
|
|
151
|
+
getOpenAIChatCompatibilityMode(draft),
|
|
155
152
|
);
|
|
156
|
-
if (choice) draft.
|
|
153
|
+
if (choice) draft.openAIChatCompatibilityMode = choice.id as OpenAIChatCompatibilityMode;
|
|
157
154
|
return;
|
|
158
155
|
}
|
|
159
156
|
if (fieldId === "authHeader") {
|
|
@@ -252,7 +249,7 @@ export async function editProvider(
|
|
|
252
249
|
t("Ctrl+S 保存并同步 models.json;不切换当前会话模型"),
|
|
253
250
|
];
|
|
254
251
|
if (draft.api === "openai-completions") {
|
|
255
|
-
summaryLines.push(
|
|
252
|
+
summaryLines.push(getOpenAIChatCompatibilityModeHint(getOpenAIChatCompatibilityMode(draft)));
|
|
256
253
|
}
|
|
257
254
|
return summaryLines;
|
|
258
255
|
};
|
package/types.ts
CHANGED
|
@@ -12,7 +12,7 @@ type ThinkingLevel = "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "
|
|
|
12
12
|
export type ThinkingLevelMap = Partial<Record<ThinkingLevel, string | null>>;
|
|
13
13
|
export type ReasoningMode = "enabled" | "disabled";
|
|
14
14
|
export type AnthropicThinkingProtocol = "adaptive" | "legacy";
|
|
15
|
-
export type
|
|
15
|
+
export type OpenAIChatCompatibilityMode = "standard" | "compatible";
|
|
16
16
|
export type BuiltInClientHeaderProfileId = "claude-code" | "codex-cli";
|
|
17
17
|
export type ClientHeaderProfileId = "recommended" | "disabled" | BuiltInClientHeaderProfileId | "custom";
|
|
18
18
|
export type CompatSettings = Record<string, unknown>;
|
|
@@ -106,8 +106,8 @@ export interface ProviderDraft {
|
|
|
106
106
|
providerId: string;
|
|
107
107
|
providerName: string;
|
|
108
108
|
api: ApiKind;
|
|
109
|
-
/** Chat Completions
|
|
110
|
-
|
|
109
|
+
/** Chat Completions 系统提示词兼容模式;standard 保持 Pi 默认判断。 */
|
|
110
|
+
openAIChatCompatibilityMode?: OpenAIChatCompatibilityMode;
|
|
111
111
|
baseUrl: string;
|
|
112
112
|
apiKey: string;
|
|
113
113
|
authHeader: boolean;
|