pi-model-manager 0.3.0 → 0.3.1
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 +8 -6
- package/README.md +7 -5
- package/atomic-write.ts +4 -2
- package/common.ts +3 -2
- package/configuration-lock.ts +3 -2
- package/configuration-persistence.ts +13 -12
- package/file-snapshot.ts +2 -1
- package/header-profile-mutations.ts +4 -3
- package/i18n.ts +403 -0
- package/index.ts +20 -9
- package/local-proxy-service.ts +10 -9
- package/model-mutations.ts +24 -21
- package/models-json-manager.ts +8 -7
- package/models-json-sync.ts +11 -10
- package/package.json +4 -2
- package/presets/client-headers.ts +9 -9
- package/presets/providers.ts +2 -2
- package/provider-registrar.ts +4 -3
- package/request-pipeline.ts +3 -2
- package/rescue.ts +4 -3
- package/state-document.ts +35 -34
- package/state-metadata-store.ts +38 -37
- package/state-store.ts +2 -1
- package/tui/dashboard.ts +75 -44
- package/tui/editor-model.ts +36 -35
- package/tui/editor-provider.ts +35 -34
- package/tui/header-profiles-panel.ts +69 -62
- package/tui/model-list-fetch.ts +9 -8
- package/tui/model-list-validation.ts +8 -7
- package/tui/model-picker.ts +13 -8
- package/tui/persistent-menu.ts +12 -11
- package/tui/ui-helpers.ts +49 -42
- package/ui-language-settings.ts +47 -0
package/tui/editor-model.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
// - 视觉支持用开关式 select,保存时仍映射为 text / text,image
|
|
8
8
|
|
|
9
9
|
import { BorderedLoader, type ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
10
|
+
import { t } from "../i18n.ts";
|
|
10
11
|
import type { AnthropicThinkingProtocol, BuiltInClientHeaderProfileId, ModelDraft, ModelListFetchOutcome, ReasoningMode, StoredClientHeaderCapture, StoredRequestHeaderProfile } from "../types.ts";
|
|
11
12
|
import { fetchModelIds } from "./model-list-fetch.ts";
|
|
12
13
|
import { pickModelIdFromList } from "./model-picker.ts";
|
|
@@ -14,8 +15,8 @@ import { showOptionPicker, showPersistentFormMenu, padLabel, type MenuCursor } f
|
|
|
14
15
|
import {
|
|
15
16
|
describeVisionInput,
|
|
16
17
|
formatApiShort,
|
|
18
|
+
getVisionInputChoices,
|
|
17
19
|
supportsVisionInput,
|
|
18
|
-
VISION_INPUT_CHOICES,
|
|
19
20
|
} from "./ui-helpers.ts";
|
|
20
21
|
|
|
21
22
|
interface FieldRow {
|
|
@@ -37,19 +38,19 @@ function shouldShowAnthropicThinkingProtocol(draft: ModelDraft): boolean {
|
|
|
37
38
|
|
|
38
39
|
|
|
39
40
|
function describeReasoningMode(mode: ReasoningMode): string {
|
|
40
|
-
return mode === "enabled" ? "开启" : "关闭";
|
|
41
|
+
return mode === "enabled" ? t("开启") : t("关闭");
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
function describeAnthropicThinkingProtocol(protocol: AnthropicThinkingProtocol): string {
|
|
44
|
-
return protocol === "adaptive" ? "开启 · 新版协议" : "关闭 · Legacy";
|
|
45
|
+
return protocol === "adaptive" ? t("开启 · 新版协议") : t("关闭 · Legacy");
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
function describeOpenAIServiceTier(draft: ModelDraft): string {
|
|
48
|
-
return draft.openAIServiceTier === "priority" ? "开启 · priority" : "关闭";
|
|
49
|
+
return draft.openAIServiceTier === "priority" ? t("开启 · priority") : t("关闭");
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
function getIntegerFieldLabel(field: "contextWindow" | "maxTokens"): string {
|
|
52
|
-
return field === "contextWindow" ? "上下文窗口" : "最大输出";
|
|
53
|
+
return field === "contextWindow" ? t("上下文窗口") : t("最大输出");
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
|
|
@@ -76,10 +77,10 @@ function applyHorizontalToggle(draft: ModelDraft, fieldId: string): boolean {
|
|
|
76
77
|
|
|
77
78
|
function buildRows(draft: ModelDraft): FieldRow[] {
|
|
78
79
|
const rows: FieldRow[] = [
|
|
79
|
-
{ id: "modelId", label: "模型 ID", value: draft.modelId || "<未填写>" },
|
|
80
|
-
{ id: "fetch", label: "重新拉取", value: "上游模型列表" },
|
|
81
|
-
{ id: "modelName", label: "显示名称", value: draft.modelName || "默认 = 模型 ID" },
|
|
82
|
-
{ id: "visionInput", label: "视觉支持", value: describeVisionInput(draft.inputKinds), adjustable: true },
|
|
80
|
+
{ id: "modelId", label: t("模型 ID"), value: draft.modelId || t("<未填写>") },
|
|
81
|
+
{ id: "fetch", label: t("重新拉取"), value: t("上游模型列表") },
|
|
82
|
+
{ id: "modelName", label: t("显示名称"), value: draft.modelName || t("默认 = 模型 ID") },
|
|
83
|
+
{ id: "visionInput", label: t("视觉支持"), value: describeVisionInput(draft.inputKinds), adjustable: true },
|
|
83
84
|
{ id: "reasoning", label: "Thinking", value: describeReasoningMode(draft.reasoningMode), adjustable: true },
|
|
84
85
|
];
|
|
85
86
|
if (shouldShowAnthropicThinkingProtocol(draft)) {
|
|
@@ -94,8 +95,8 @@ function buildRows(draft: ModelDraft): FieldRow[] {
|
|
|
94
95
|
rows.push({ id: "openAIServiceTier", label: "Fast mode", value: describeOpenAIServiceTier(draft), adjustable: true });
|
|
95
96
|
}
|
|
96
97
|
rows.push(
|
|
97
|
-
{ id: "contextWindow", label: "上下文窗口", value: String(draft.contextWindow) },
|
|
98
|
-
{ id: "maxTokens", label: "最大输出", value: String(draft.maxTokens) },
|
|
98
|
+
{ id: "contextWindow", label: t("上下文窗口"), value: String(draft.contextWindow) },
|
|
99
|
+
{ id: "maxTokens", label: t("最大输出"), value: String(draft.maxTokens) },
|
|
99
100
|
);
|
|
100
101
|
return rows;
|
|
101
102
|
}
|
|
@@ -127,7 +128,7 @@ async function pickModelFromUpstream(
|
|
|
127
128
|
clientHeaderCaptures,
|
|
128
129
|
};
|
|
129
130
|
const outcome = await ctx.ui.custom<ModelListFetchOutcome>((tui, theme, _keybindings, done) => {
|
|
130
|
-
const loader = new BorderedLoader(tui, theme, "正在拉取模型列表,总计最多 10 秒…", { cancellable: true });
|
|
131
|
+
const loader = new BorderedLoader(tui, theme, t("正在拉取模型列表,总计最多 10 秒…"), { cancellable: true });
|
|
131
132
|
let settled = false;
|
|
132
133
|
const finish = (result: ModelListFetchOutcome) => {
|
|
133
134
|
if (settled) return;
|
|
@@ -142,20 +143,20 @@ async function pickModelFromUpstream(
|
|
|
142
143
|
});
|
|
143
144
|
if (outcome.status === "cancelled") return;
|
|
144
145
|
if (outcome.status === "failed") {
|
|
145
|
-
ctx.ui.notify(
|
|
146
|
-
const fallback = await ctx.ui.input(
|
|
146
|
+
ctx.ui.notify(t("拉取失败:{error}", { error: outcome.message }), "warning");
|
|
147
|
+
const fallback = await ctx.ui.input(t("手动输入模型 ID(当前:{current})", { current: draft.modelId || t("<空>") }), draft.modelId);
|
|
147
148
|
if (fallback !== undefined) {
|
|
148
149
|
draft.modelId = fallback.trim() || draft.modelId;
|
|
149
150
|
}
|
|
150
151
|
return;
|
|
151
152
|
}
|
|
152
153
|
if (outcome.modelIds.length === 0) {
|
|
153
|
-
ctx.ui.notify("上游返回空列表", "warning");
|
|
154
|
+
ctx.ui.notify(t("上游返回空列表"), "warning");
|
|
154
155
|
return;
|
|
155
156
|
}
|
|
156
157
|
const picked = await pickModelIdFromList(
|
|
157
158
|
ctx,
|
|
158
|
-
|
|
159
|
+
t("选择模型 ID(共 {count} 个)", { count: outcome.modelIds.length }),
|
|
159
160
|
outcome.modelIds,
|
|
160
161
|
draft.modelId,
|
|
161
162
|
);
|
|
@@ -167,13 +168,13 @@ async function pickModelFromUpstream(
|
|
|
167
168
|
async function editIntField(ctx: ExtensionCommandContext, draft: ModelDraft, field: "contextWindow" | "maxTokens"): Promise<void> {
|
|
168
169
|
const label = getIntegerFieldLabel(field);
|
|
169
170
|
const current = String(draft[field]);
|
|
170
|
-
const value = await ctx.ui.input(
|
|
171
|
+
const value = await ctx.ui.input(t("{label}(当前:{current},留空保持原值)", { label, current }), current);
|
|
171
172
|
if (value === undefined) return;
|
|
172
173
|
const trimmed = value.trim();
|
|
173
174
|
if (!trimmed) return;
|
|
174
175
|
const parsed = Number.parseInt(trimmed, 10);
|
|
175
176
|
if (!Number.isFinite(parsed) || parsed <= 0) {
|
|
176
|
-
ctx.ui.notify(
|
|
177
|
+
ctx.ui.notify(t("{label} 必须是正整数", { label }), "warning");
|
|
177
178
|
return;
|
|
178
179
|
}
|
|
179
180
|
draft[field] = parsed;
|
|
@@ -187,7 +188,7 @@ async function editField(
|
|
|
187
188
|
clientHeaderCaptures: Partial<Record<BuiltInClientHeaderProfileId, StoredClientHeaderCapture>>,
|
|
188
189
|
): Promise<void> {
|
|
189
190
|
if (fieldId === "modelId") {
|
|
190
|
-
const value = await ctx.ui.input(
|
|
191
|
+
const value = await ctx.ui.input(t("模型 ID(当前:{current},传给上游 API 的模型字段)", { current: draft.modelId || t("<空>") }), draft.modelId);
|
|
191
192
|
if (value !== undefined) {
|
|
192
193
|
const trimmed = value.trim();
|
|
193
194
|
if (trimmed) {
|
|
@@ -201,17 +202,17 @@ async function editField(
|
|
|
201
202
|
return;
|
|
202
203
|
}
|
|
203
204
|
if (fieldId === "modelName") {
|
|
204
|
-
const value = await ctx.ui.input(
|
|
205
|
+
const value = await ctx.ui.input(t("显示名称(当前:{current},可空默认用模型 ID;输入空格清空)", { current: draft.modelName || t("<空>") }), draft.modelName);
|
|
205
206
|
if (value !== undefined) draft.modelName = value.trim();
|
|
206
207
|
return;
|
|
207
208
|
}
|
|
208
209
|
if (fieldId === "visionInput") {
|
|
209
|
-
const choices =
|
|
210
|
+
const choices = getVisionInputChoices().map((choice) => ({
|
|
210
211
|
id: choice.enabled ? "enabled" : "disabled",
|
|
211
212
|
label: choice.label,
|
|
212
213
|
kinds: choice.kinds,
|
|
213
214
|
}));
|
|
214
|
-
const choice = await showOptionPicker(ctx, "视觉支持", choices, supportsVisionInput(draft.inputKinds) ? "enabled" : "disabled");
|
|
215
|
+
const choice = await showOptionPicker(ctx, t("视觉支持"), choices, supportsVisionInput(draft.inputKinds) ? "enabled" : "disabled");
|
|
215
216
|
if (choice) draft.inputKinds = [...choice.kinds];
|
|
216
217
|
return;
|
|
217
218
|
}
|
|
@@ -220,8 +221,8 @@ async function editField(
|
|
|
220
221
|
ctx,
|
|
221
222
|
"Thinking",
|
|
222
223
|
[
|
|
223
|
-
{ id: "disabled" as ReasoningMode, label: "关闭 — 不发送模型推理参数" },
|
|
224
|
-
{ id: "enabled" as ReasoningMode, label: "开启 — 启用模型推理参数" },
|
|
224
|
+
{ id: "disabled" as ReasoningMode, label: t("关闭 — 不发送模型推理参数") },
|
|
225
|
+
{ id: "enabled" as ReasoningMode, label: t("开启 — 启用模型推理参数") },
|
|
225
226
|
],
|
|
226
227
|
draft.reasoningMode,
|
|
227
228
|
);
|
|
@@ -233,8 +234,8 @@ async function editField(
|
|
|
233
234
|
ctx,
|
|
234
235
|
"Adaptive",
|
|
235
236
|
[
|
|
236
|
-
{ id: "adaptive" as AnthropicThinkingProtocol, label: "开启:新版模型,发送 thinking.type=adaptive 和 output_config.effort" },
|
|
237
|
-
{ id: "legacy" as AnthropicThinkingProtocol, label: "关闭:旧版接口,发送 thinking.type=enabled 和 budget_tokens" },
|
|
237
|
+
{ id: "adaptive" as AnthropicThinkingProtocol, label: t("开启:新版模型,发送 thinking.type=adaptive 和 output_config.effort") },
|
|
238
|
+
{ id: "legacy" as AnthropicThinkingProtocol, label: t("关闭:旧版接口,发送 thinking.type=enabled 和 budget_tokens") },
|
|
238
239
|
],
|
|
239
240
|
draft.anthropicThinkingProtocol ?? "legacy",
|
|
240
241
|
);
|
|
@@ -246,8 +247,8 @@ async function editField(
|
|
|
246
247
|
ctx,
|
|
247
248
|
"Fast mode",
|
|
248
249
|
[
|
|
249
|
-
{ id: "disabled", tier: undefined, label: "关闭 — 不发送 service_tier(默认)" },
|
|
250
|
-
{ id: "priority", tier: "priority", label: "开启 — service_tier=priority,可能消耗 Fast / priority 额度" },
|
|
250
|
+
{ id: "disabled", tier: undefined, label: t("关闭 — 不发送 service_tier(默认)") },
|
|
251
|
+
{ id: "priority", tier: "priority", label: t("开启 — service_tier=priority,可能消耗 Fast / priority 额度") },
|
|
251
252
|
] as const satisfies readonly { id: string; tier: ModelDraft["openAIServiceTier"]; label: string }[],
|
|
252
253
|
draft.openAIServiceTier === "priority" ? "priority" : "disabled",
|
|
253
254
|
);
|
|
@@ -291,19 +292,19 @@ export async function editModel(
|
|
|
291
292
|
cursor,
|
|
292
293
|
{
|
|
293
294
|
summaryLines: [
|
|
294
|
-
|
|
295
|
-
"Ctrl+S 保存并启用模型;不切换当前会话模型",
|
|
295
|
+
t("接入 {providerId} · API {api}", { providerId: draft.providerId, api: formatApiShort(draft.api) }),
|
|
296
|
+
t("Ctrl+S 保存并启用模型;不切换当前会话模型"),
|
|
296
297
|
],
|
|
297
298
|
onAdjust: (id) => {
|
|
298
299
|
if (!applyHorizontalToggle(draft, id)) return undefined;
|
|
299
300
|
return toMenuRows(buildRows(draft));
|
|
300
301
|
},
|
|
301
302
|
hints: [
|
|
302
|
-
{ key: "↑↓", label: "选择" },
|
|
303
|
-
{ key: "←→", label: "切换选项" },
|
|
304
|
-
{ key: "Enter", label: "编辑" },
|
|
305
|
-
{ key: "Ctrl+S", label: "保存并启用" },
|
|
306
|
-
{ key: "Esc", label: "返回" },
|
|
303
|
+
{ key: "↑↓", label: t("选择") },
|
|
304
|
+
{ key: "←→", label: t("切换选项") },
|
|
305
|
+
{ key: "Enter", label: t("编辑") },
|
|
306
|
+
{ key: "Ctrl+S", label: t("保存并启用") },
|
|
307
|
+
{ key: "Esc", label: t("返回") },
|
|
307
308
|
],
|
|
308
309
|
},
|
|
309
310
|
);
|
package/tui/editor-provider.ts
CHANGED
|
@@ -5,16 +5,17 @@
|
|
|
5
5
|
|
|
6
6
|
import type { ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
7
7
|
import { hasStringRecordEntries } from "../common.ts";
|
|
8
|
+
import { t } from "../i18n.ts";
|
|
8
9
|
import { switchProviderDraftApiPreset } from "../presets/providers.ts";
|
|
9
10
|
import { redactUrlForDisplay } from "../sensitive-redaction.ts";
|
|
10
11
|
import { resolveRuntimeBaseUrl } from "../runtime-base-url.ts";
|
|
11
12
|
import { DEFAULT_PROVIDER_HTTP_PROXY_URL } from "../types.ts";
|
|
12
13
|
import { showOptionPicker, showPersistentFormMenu, padLabel, type MenuCursor } from "./persistent-menu.ts";
|
|
13
14
|
import {
|
|
14
|
-
API_CHOICES,
|
|
15
|
-
BUILT_IN_PROFILE_CHOICES,
|
|
16
15
|
describeProfile,
|
|
17
16
|
formatApiShort,
|
|
17
|
+
getApiChoices,
|
|
18
|
+
getBuiltInProfileChoices,
|
|
18
19
|
maskSecret,
|
|
19
20
|
} from "./ui-helpers.ts";
|
|
20
21
|
import type { ClientHeaderProfileId, ProviderDraft, StoredRequestHeaderProfile } from "../types.ts";
|
|
@@ -35,18 +36,18 @@ function buildRows(
|
|
|
35
36
|
&& !draft.requestHeaderProfileId
|
|
36
37
|
&& hasStringRecordEntries(draft.customClientHeaders);
|
|
37
38
|
const profileDisplay = inlineCustomProfile
|
|
38
|
-
?
|
|
39
|
+
? t("内联自定义请求头({count}项)", { count: Object.keys(draft.customClientHeaders).length })
|
|
39
40
|
: describeProfile(draft.clientHeaderProfile, draft.api, draft.requestHeaderProfileId, requestHeaderProfiles);
|
|
40
41
|
return [
|
|
41
|
-
{ id: "api", label: "API 协议", value: draft.api },
|
|
42
|
-
{ id: "providerId", label: "接入 ID(必填)", value: draft.providerId || "<必填>" },
|
|
43
|
-
{ id: "providerName", label: "名称", value: draft.providerName || "<空>" },
|
|
42
|
+
{ id: "api", label: t("API 协议"), value: draft.api },
|
|
43
|
+
{ id: "providerId", label: t("接入 ID(必填)"), value: draft.providerId || t("<必填>") },
|
|
44
|
+
{ id: "providerName", label: t("名称"), value: draft.providerName || t("<空>") },
|
|
44
45
|
{ id: "baseUrl", label: "Base URL", value: draft.baseUrl },
|
|
45
|
-
{ id: "httpProxyEnabled", label: "本机代理", value: draft.httpProxyEnabled ? "开启" : "关闭", adjustable: true },
|
|
46
|
-
{ id: "httpProxyUrl", label: "代理地址", value: draft.httpProxyEnabled ? redactUrlForDisplay(draft.httpProxyUrl || DEFAULT_PROVIDER_HTTP_PROXY_URL) : "关闭时不使用" },
|
|
46
|
+
{ id: "httpProxyEnabled", label: t("本机代理"), value: draft.httpProxyEnabled ? t("开启") : t("关闭"), adjustable: true },
|
|
47
|
+
{ id: "httpProxyUrl", label: t("代理地址"), value: draft.httpProxyEnabled ? redactUrlForDisplay(draft.httpProxyUrl || DEFAULT_PROVIDER_HTTP_PROXY_URL) : t("关闭时不使用") },
|
|
47
48
|
{ id: "apiKey", label: "API key", value: maskSecret(draft.apiKey) },
|
|
48
|
-
{ id: "authHeader", label: "认证头", value: draft.authHeader ? "Bearer" : "默认" },
|
|
49
|
-
{ id: "clientHeaderProfile", label: "请求头", value: profileDisplay },
|
|
49
|
+
{ id: "authHeader", label: t("认证头"), value: draft.authHeader ? "Bearer" : t("默认") },
|
|
50
|
+
{ id: "clientHeaderProfile", label: t("请求头"), value: profileDisplay },
|
|
50
51
|
];
|
|
51
52
|
}
|
|
52
53
|
|
|
@@ -66,18 +67,18 @@ async function editClientHeaderProfile(
|
|
|
66
67
|
requestHeaderProfiles: Record<string, StoredRequestHeaderProfile>,
|
|
67
68
|
): Promise<void> {
|
|
68
69
|
const choices = [
|
|
69
|
-
...
|
|
70
|
+
...getBuiltInProfileChoices().map((choice) => ({ id: choice.id as string, label: choice.label })),
|
|
70
71
|
...Object.entries(requestHeaderProfiles)
|
|
71
72
|
.sort(([a], [b]) => a.localeCompare(b))
|
|
72
73
|
.map(([profileId, profile]) => ({
|
|
73
74
|
id: `custom:${profileId}`,
|
|
74
|
-
label:
|
|
75
|
+
label: t("自定义:{id} — {name}", { id: profileId, name: profile.name }),
|
|
75
76
|
})),
|
|
76
77
|
];
|
|
77
78
|
const currentId = draft.clientHeaderProfile === "custom" && draft.requestHeaderProfileId
|
|
78
79
|
? `custom:${draft.requestHeaderProfileId}`
|
|
79
80
|
: draft.clientHeaderProfile;
|
|
80
|
-
const choice = await showOptionPicker(ctx, "请求头", choices, currentId);
|
|
81
|
+
const choice = await showOptionPicker(ctx, t("请求头"), choices, currentId);
|
|
81
82
|
if (!choice) return;
|
|
82
83
|
if (choice.id.startsWith("custom:")) {
|
|
83
84
|
draft.clientHeaderProfile = "custom";
|
|
@@ -95,17 +96,17 @@ async function editField(
|
|
|
95
96
|
requestHeaderProfiles: Record<string, StoredRequestHeaderProfile>,
|
|
96
97
|
): Promise<void> {
|
|
97
98
|
if (fieldId === "api") {
|
|
98
|
-
const choice = await showOptionPicker(ctx, "选择 API 协议",
|
|
99
|
+
const choice = await showOptionPicker(ctx, t("选择 API 协议"), getApiChoices(), draft.api);
|
|
99
100
|
if (choice) switchProviderDraftApiPreset(draft, choice.id);
|
|
100
101
|
return;
|
|
101
102
|
}
|
|
102
103
|
if (fieldId === "authHeader") {
|
|
103
104
|
const choice = await showOptionPicker(
|
|
104
105
|
ctx,
|
|
105
|
-
"认证头(API key 放在哪里)",
|
|
106
|
+
t("认证头(API key 放在哪里)"),
|
|
106
107
|
[
|
|
107
|
-
{ id: "default", label: "默认 — 交给协议 SDK / 接入默认行为" },
|
|
108
|
-
{ id: "bearer", label: "Bearer — 强制 Authorization: Bearer <apiKey>" },
|
|
108
|
+
{ id: "default", label: t("默认 — 交给协议 SDK / 接入默认行为") },
|
|
109
|
+
{ id: "bearer", label: t("Bearer — 强制 Authorization: Bearer <apiKey>") },
|
|
109
110
|
],
|
|
110
111
|
draft.authHeader ? "bearer" : "default",
|
|
111
112
|
);
|
|
@@ -119,10 +120,10 @@ async function editField(
|
|
|
119
120
|
if (fieldId === "httpProxyEnabled") {
|
|
120
121
|
const choice = await showOptionPicker(
|
|
121
122
|
ctx,
|
|
122
|
-
"本机代理(仅当前接入点)",
|
|
123
|
+
t("本机代理(仅当前接入点)"),
|
|
123
124
|
[
|
|
124
|
-
{ id: "disabled", label: "关闭 — 请求直连上游" },
|
|
125
|
-
{ id: "enabled", label:
|
|
125
|
+
{ id: "disabled", label: t("关闭 — 请求直连上游") },
|
|
126
|
+
{ id: "enabled", label: t("开启 — 通过 {url}", { url: redactUrlForDisplay(draft.httpProxyUrl || DEFAULT_PROVIDER_HTTP_PROXY_URL) }) },
|
|
126
127
|
],
|
|
127
128
|
draft.httpProxyEnabled ? "enabled" : "disabled",
|
|
128
129
|
);
|
|
@@ -133,33 +134,33 @@ async function editField(
|
|
|
133
134
|
}
|
|
134
135
|
if (fieldId === "providerId") {
|
|
135
136
|
const value = await ctx.ui.input(
|
|
136
|
-
|
|
137
|
+
t("接入 ID(必填,最多 48 个字符;仅字母、数字、点、下划线和连字符;当前:{current})", { current: draft.providerId || t("<空>") }),
|
|
137
138
|
draft.providerId,
|
|
138
139
|
);
|
|
139
140
|
if (value !== undefined) draft.providerId = value.trim();
|
|
140
141
|
return;
|
|
141
142
|
}
|
|
142
143
|
if (fieldId === "providerName") {
|
|
143
|
-
const value = await ctx.ui.input(
|
|
144
|
+
const value = await ctx.ui.input(t("名称(显示用,可留空;当前:{current})", { current: draft.providerName || t("<空>") }), draft.providerName);
|
|
144
145
|
if (value !== undefined) draft.providerName = value.trim();
|
|
145
146
|
return;
|
|
146
147
|
}
|
|
147
148
|
if (fieldId === "httpProxyUrl") {
|
|
148
149
|
const currentLabel = redactUrlForDisplay(draft.httpProxyUrl || DEFAULT_PROVIDER_HTTP_PROXY_URL);
|
|
149
|
-
const value = await ctx.ui.input(
|
|
150
|
+
const value = await ctx.ui.input(t("代理地址(http/https;当前:{current},留空保持原值)", { current: currentLabel }), "");
|
|
150
151
|
if (value?.trim()) draft.httpProxyUrl = value.trim();
|
|
151
152
|
return;
|
|
152
153
|
}
|
|
153
154
|
if (fieldId === "apiKey") {
|
|
154
|
-
const currentLabel = draft.apiKey ? maskSecret(draft.apiKey) : "<空>";
|
|
155
|
-
const value = await ctx.ui.input(
|
|
155
|
+
const currentLabel = draft.apiKey ? maskSecret(draft.apiKey) : t("<空>");
|
|
156
|
+
const value = await ctx.ui.input(t("API key(可选;明文 / $ENV_VAR / !command;当前:{current},留空清除)", { current: currentLabel }), "");
|
|
156
157
|
if (value === undefined) return;
|
|
157
158
|
draft.apiKey = value.trim();
|
|
158
159
|
return;
|
|
159
160
|
}
|
|
160
161
|
// [喵喵喵]: baseUrl 是唯一走通用文本输入的字段,显式列出才能保持 draft 的类型检查。
|
|
161
162
|
if (fieldId !== "baseUrl") return;
|
|
162
|
-
const value = await ctx.ui.input(
|
|
163
|
+
const value = await ctx.ui.input(t("Base URL(http/https)(当前:{current},留空保持原值)", { current: draft.baseUrl || t("<空>") }), draft.baseUrl);
|
|
163
164
|
if (value === undefined) return;
|
|
164
165
|
const trimmed = value.trim();
|
|
165
166
|
if (!trimmed) return;
|
|
@@ -196,20 +197,20 @@ export async function editProvider(
|
|
|
196
197
|
cursor,
|
|
197
198
|
{
|
|
198
199
|
summaryLines: [
|
|
199
|
-
`API ${formatApiShort(draft.api)} · 请求头 ${describeProfile(draft.clientHeaderProfile, draft.api, draft.requestHeaderProfileId, requestHeaderProfiles)}`,
|
|
200
|
-
"接入 ID 必填,且不能与已有或 pi 内置接入重复",
|
|
201
|
-
"Ctrl+S 保存并同步 models.json;不切换当前会话模型",
|
|
200
|
+
`API ${formatApiShort(draft.api)} · ${t("请求头")} ${describeProfile(draft.clientHeaderProfile, draft.api, draft.requestHeaderProfileId, requestHeaderProfiles)}`,
|
|
201
|
+
t("接入 ID 必填,且不能与已有或 pi 内置接入重复"),
|
|
202
|
+
t("Ctrl+S 保存并同步 models.json;不切换当前会话模型"),
|
|
202
203
|
],
|
|
203
204
|
onAdjust: (id) => {
|
|
204
205
|
if (!applyHorizontalToggle(draft, id)) return undefined;
|
|
205
206
|
return toMenuRows(buildRows(draft, requestHeaderProfiles));
|
|
206
207
|
},
|
|
207
208
|
hints: [
|
|
208
|
-
{ key: "↑↓", label: "选择" },
|
|
209
|
-
{ key: "←→", label: "切换选项" },
|
|
210
|
-
{ key: "Enter", label: "编辑" },
|
|
211
|
-
{ key: "Ctrl+S", label: "保存并同步" },
|
|
212
|
-
{ key: "Esc", label: "返回" },
|
|
209
|
+
{ key: "↑↓", label: t("选择") },
|
|
210
|
+
{ key: "←→", label: t("切换选项") },
|
|
211
|
+
{ key: "Enter", label: t("编辑") },
|
|
212
|
+
{ key: "Ctrl+S", label: t("保存并同步") },
|
|
213
|
+
{ key: "Esc", label: t("返回") },
|
|
213
214
|
],
|
|
214
215
|
},
|
|
215
216
|
);
|