pi-model-manager 0.4.9 → 0.4.10
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 +47 -130
- package/README.md +47 -130
- package/common.ts +6 -3
- package/configuration-persistence.ts +39 -52
- package/header-profile-mutations.ts +13 -38
- package/i18n.ts +11 -130
- package/index.ts +13 -11
- package/model-mutations.ts +75 -125
- package/model-request-headers.ts +54 -0
- package/models-json-sync.ts +13 -13
- package/package.json +2 -1
- package/presets/builtin-client-headers.ts +9 -4
- package/presets/client-headers.ts +9 -18
- package/presets/providers.ts +0 -10
- package/presets/thinking.ts +5 -69
- package/provider-registrar.ts +11 -59
- package/provider-transport.ts +5 -7
- package/request-pipeline.ts +10 -0
- package/rescue.ts +10 -16
- package/state-document.ts +26 -32
- package/state-metadata-store.ts +23 -58
- package/state-store.ts +8 -16
- package/tui/model-list-fetch.ts +2 -6
- package/tui/model-search.ts +45 -0
- package/tui/model-values.ts +24 -0
- package/tui/ui-helpers.ts +68 -157
- package/tui/workbench-fields.ts +127 -0
- package/tui/workbench-headers.ts +80 -0
- package/tui/workbench-types.ts +67 -0
- package/tui/workbench-window.ts +439 -0
- package/tui/workbench.ts +385 -0
- package/types.ts +9 -14
- package/tui/dashboard.ts +0 -463
- package/tui/editor-model.ts +0 -391
- package/tui/editor-provider.ts +0 -368
- package/tui/header-profiles-panel.ts +0 -407
- package/tui/model-picker.ts +0 -273
- package/tui/persistent-menu.ts +0 -590
package/tui/editor-provider.ts
DELETED
|
@@ -1,368 +0,0 @@
|
|
|
1
|
-
// tui/editor-provider.ts
|
|
2
|
-
//
|
|
3
|
-
// 接入编辑器:问答式表单(custom menu + input/select 拼装)。
|
|
4
|
-
// 用户可以反复编辑字段;Ctrl+S 保存,Esc 返回。
|
|
5
|
-
|
|
6
|
-
import type { ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
7
|
-
import { hasStringRecordEntries } from "../common.ts";
|
|
8
|
-
import { t } from "../i18n.ts";
|
|
9
|
-
import { switchProviderDraftApiPreset } from "../presets/providers.ts";
|
|
10
|
-
import { redactUrlForDisplay } from "../sensitive-redaction.ts";
|
|
11
|
-
import { resolveProviderDraftBaseUrl, validateRequestBaseUrl } from "../runtime-base-url.ts";
|
|
12
|
-
import {
|
|
13
|
-
DEFAULT_PROVIDER_HTTP_PROXY_URL,
|
|
14
|
-
type OpenAIChatCompatibilityMode,
|
|
15
|
-
type OpenAIResponsesStreamCompletionMode,
|
|
16
|
-
} from "../types.ts";
|
|
17
|
-
import { showOptionPicker, showPersistentFormMenu, padLabel, markAdjustableValue, type HorizontalDirection, type MenuCursor } from "./persistent-menu.ts";
|
|
18
|
-
import {
|
|
19
|
-
describeProfile,
|
|
20
|
-
formatApiShort,
|
|
21
|
-
getApiChoices,
|
|
22
|
-
getBuiltInProfileChoices,
|
|
23
|
-
maskSecret,
|
|
24
|
-
} from "./ui-helpers.ts";
|
|
25
|
-
import type { ClientHeaderProfileId, ProviderDraft, StoredRequestHeaderProfile } from "../types.ts";
|
|
26
|
-
|
|
27
|
-
interface FieldRow {
|
|
28
|
-
id: string;
|
|
29
|
-
label: string;
|
|
30
|
-
value: string;
|
|
31
|
-
// 开关类字段可用 ←→ 就地切换;其余字段需要 Enter 进入输入或选择器。
|
|
32
|
-
adjustable?: boolean;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const OPENAI_CHAT_COMPATIBILITY_MODE_ORDER: readonly OpenAIChatCompatibilityMode[] = ["standard", "compatible"];
|
|
36
|
-
const OPENAI_RESPONSES_STREAM_COMPLETION_MODE_ORDER: readonly OpenAIResponsesStreamCompletionMode[] = ["standard", "terminal-event"];
|
|
37
|
-
|
|
38
|
-
function getOpenAIChatCompatibilityMode(draft: ProviderDraft): OpenAIChatCompatibilityMode {
|
|
39
|
-
return draft.openAIChatCompatibilityMode ?? "standard";
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function describeOpenAIChatCompatibilityMode(mode: OpenAIChatCompatibilityMode): string {
|
|
43
|
-
if (mode === "compatible") return t("兼容 · system");
|
|
44
|
-
return t("标准 · Pi 默认");
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function getOpenAIChatCompatibilityModeHint(mode: OpenAIChatCompatibilityMode): string {
|
|
48
|
-
if (mode === "compatible") return t("兼容模式:系统提示词强制使用 system role,适合忽略 developer 的中转。");
|
|
49
|
-
return t("标准模式:保持 Pi 默认兼容判断。");
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function cycleOpenAIChatCompatibilityMode(
|
|
53
|
-
mode: OpenAIChatCompatibilityMode,
|
|
54
|
-
direction: HorizontalDirection,
|
|
55
|
-
): OpenAIChatCompatibilityMode {
|
|
56
|
-
const index = OPENAI_CHAT_COMPATIBILITY_MODE_ORDER.indexOf(mode);
|
|
57
|
-
const offset = direction === "right" ? 1 : -1;
|
|
58
|
-
return OPENAI_CHAT_COMPATIBILITY_MODE_ORDER[(index + offset + OPENAI_CHAT_COMPATIBILITY_MODE_ORDER.length) % OPENAI_CHAT_COMPATIBILITY_MODE_ORDER.length]!;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function getOpenAIResponsesStreamCompletionMode(draft: ProviderDraft): OpenAIResponsesStreamCompletionMode {
|
|
62
|
-
return draft.openAIResponsesStreamCompletionMode ?? "standard";
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function describeOpenAIResponsesStreamCompletionMode(mode: OpenAIResponsesStreamCompletionMode): string {
|
|
66
|
-
if (mode === "terminal-event") return t("兼容 · 终态即结束");
|
|
67
|
-
return t("标准 · 等待连接关闭");
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function getOpenAIResponsesStreamCompletionModeHint(mode: OpenAIResponsesStreamCompletionMode): string {
|
|
71
|
-
if (mode === "terminal-event") return t("兼容模式:正式终态事件已转交后主动结束,不等待上游关闭连接。");
|
|
72
|
-
return t("标准模式:等待上游正常结束流。若回复完成后长期卡住,可启用兼容模式。");
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function cycleOpenAIResponsesStreamCompletionMode(
|
|
76
|
-
mode: OpenAIResponsesStreamCompletionMode,
|
|
77
|
-
direction: HorizontalDirection,
|
|
78
|
-
): OpenAIResponsesStreamCompletionMode {
|
|
79
|
-
const index = OPENAI_RESPONSES_STREAM_COMPLETION_MODE_ORDER.indexOf(mode);
|
|
80
|
-
const offset = direction === "right" ? 1 : -1;
|
|
81
|
-
return OPENAI_RESPONSES_STREAM_COMPLETION_MODE_ORDER[(index + offset + OPENAI_RESPONSES_STREAM_COMPLETION_MODE_ORDER.length) % OPENAI_RESPONSES_STREAM_COMPLETION_MODE_ORDER.length]!;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function buildRows(
|
|
85
|
-
draft: ProviderDraft,
|
|
86
|
-
requestHeaderProfiles: Record<string, StoredRequestHeaderProfile>,
|
|
87
|
-
): FieldRow[] {
|
|
88
|
-
const inlineCustomProfile = draft.clientHeaderProfile === "custom"
|
|
89
|
-
&& !draft.requestHeaderProfileId
|
|
90
|
-
&& hasStringRecordEntries(draft.customClientHeaders);
|
|
91
|
-
const profileDisplay = inlineCustomProfile
|
|
92
|
-
? t("内联自定义请求头({count}项)", { count: Object.keys(draft.customClientHeaders).length })
|
|
93
|
-
: describeProfile(draft.clientHeaderProfile, draft.api, draft.requestHeaderProfileId, requestHeaderProfiles);
|
|
94
|
-
const rows: FieldRow[] = [
|
|
95
|
-
{ id: "api", label: t("API 协议"), value: draft.api },
|
|
96
|
-
{ id: "providerId", label: t("接入 ID(必填)"), value: draft.providerId || t("<必填>") },
|
|
97
|
-
{ id: "providerName", label: t("名称"), value: draft.providerName || t("<空>") },
|
|
98
|
-
{ id: "baseUrl", label: "Base URL", value: redactUrlForDisplay(draft.baseUrl) },
|
|
99
|
-
];
|
|
100
|
-
if (draft.api === "openai-completions") {
|
|
101
|
-
rows.push({
|
|
102
|
-
id: "openAIChatCompatibilityMode",
|
|
103
|
-
label: t("协议兼容"),
|
|
104
|
-
value: describeOpenAIChatCompatibilityMode(getOpenAIChatCompatibilityMode(draft)),
|
|
105
|
-
adjustable: true,
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
if (draft.api === "openai-responses") {
|
|
109
|
-
rows.push({
|
|
110
|
-
id: "openAIResponsesStreamCompletionMode",
|
|
111
|
-
label: t("流结束兼容"),
|
|
112
|
-
value: describeOpenAIResponsesStreamCompletionMode(getOpenAIResponsesStreamCompletionMode(draft)),
|
|
113
|
-
adjustable: true,
|
|
114
|
-
});
|
|
115
|
-
rows.push({
|
|
116
|
-
id: "openAIResponsesAutoRecoveryEnabled",
|
|
117
|
-
label: t("跨资源自动恢复"),
|
|
118
|
-
value: draft.openAIResponsesAutoRecoveryEnabled ? t("开启") : t("关闭"),
|
|
119
|
-
adjustable: true,
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
rows.push(
|
|
123
|
-
{ id: "httpProxyEnabled", label: t("本机代理"), value: draft.httpProxyEnabled ? t("开启") : t("关闭"), adjustable: true },
|
|
124
|
-
{ id: "httpProxyUrl", label: t("代理地址"), value: draft.httpProxyEnabled ? redactUrlForDisplay(draft.httpProxyUrl || DEFAULT_PROVIDER_HTTP_PROXY_URL) : t("关闭时不使用") },
|
|
125
|
-
{ id: "apiKey", label: "API key", value: maskSecret(draft.apiKey) },
|
|
126
|
-
{ id: "authHeader", label: t("认证头"), value: draft.authHeader ? "Bearer" : t("默认") },
|
|
127
|
-
{ id: "clientHeaderProfile", label: t("请求头"), value: profileDisplay },
|
|
128
|
-
);
|
|
129
|
-
return rows;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
// 二值开关的两个方向都取反。
|
|
135
|
-
function applyHorizontalToggle(draft: ProviderDraft, fieldId: string, direction: HorizontalDirection): boolean {
|
|
136
|
-
if (fieldId === "openAIChatCompatibilityMode") {
|
|
137
|
-
draft.openAIChatCompatibilityMode = cycleOpenAIChatCompatibilityMode(getOpenAIChatCompatibilityMode(draft), direction);
|
|
138
|
-
return true;
|
|
139
|
-
}
|
|
140
|
-
if (fieldId === "openAIResponsesStreamCompletionMode") {
|
|
141
|
-
draft.openAIResponsesStreamCompletionMode = cycleOpenAIResponsesStreamCompletionMode(getOpenAIResponsesStreamCompletionMode(draft), direction);
|
|
142
|
-
return true;
|
|
143
|
-
}
|
|
144
|
-
if (fieldId === "openAIResponsesAutoRecoveryEnabled") {
|
|
145
|
-
draft.openAIResponsesAutoRecoveryEnabled = !draft.openAIResponsesAutoRecoveryEnabled;
|
|
146
|
-
return true;
|
|
147
|
-
}
|
|
148
|
-
if (fieldId !== "httpProxyEnabled") return false;
|
|
149
|
-
draft.httpProxyEnabled = !draft.httpProxyEnabled;
|
|
150
|
-
if (draft.httpProxyEnabled && !draft.httpProxyUrl.trim()) draft.httpProxyUrl = DEFAULT_PROVIDER_HTTP_PROXY_URL;
|
|
151
|
-
return true;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
async function editClientHeaderProfile(
|
|
155
|
-
ctx: ExtensionCommandContext,
|
|
156
|
-
draft: ProviderDraft,
|
|
157
|
-
requestHeaderProfiles: Record<string, StoredRequestHeaderProfile>,
|
|
158
|
-
): Promise<void> {
|
|
159
|
-
const choices = [
|
|
160
|
-
...getBuiltInProfileChoices().map((choice) => ({ id: choice.id as string, label: choice.label })),
|
|
161
|
-
...Object.entries(requestHeaderProfiles)
|
|
162
|
-
.sort(([a], [b]) => a.localeCompare(b))
|
|
163
|
-
.map(([profileId, profile]) => ({
|
|
164
|
-
id: `custom:${profileId}`,
|
|
165
|
-
label: t("自定义:{id} — {name}", { id: profileId, name: profile.name }),
|
|
166
|
-
})),
|
|
167
|
-
];
|
|
168
|
-
const currentId = draft.clientHeaderProfile === "custom" && draft.requestHeaderProfileId
|
|
169
|
-
? `custom:${draft.requestHeaderProfileId}`
|
|
170
|
-
: draft.clientHeaderProfile;
|
|
171
|
-
const choice = await showOptionPicker(ctx, t("请求头"), choices, currentId);
|
|
172
|
-
if (!choice) return;
|
|
173
|
-
if (choice.id.startsWith("custom:")) {
|
|
174
|
-
draft.clientHeaderProfile = "custom";
|
|
175
|
-
draft.requestHeaderProfileId = choice.id.slice("custom:".length);
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
draft.clientHeaderProfile = choice.id as ClientHeaderProfileId;
|
|
179
|
-
delete draft.requestHeaderProfileId;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
async function editField(
|
|
183
|
-
ctx: ExtensionCommandContext,
|
|
184
|
-
draft: ProviderDraft,
|
|
185
|
-
fieldId: string,
|
|
186
|
-
requestHeaderProfiles: Record<string, StoredRequestHeaderProfile>,
|
|
187
|
-
): Promise<void> {
|
|
188
|
-
if (fieldId === "api") {
|
|
189
|
-
const choice = await showOptionPicker(ctx, t("选择 API 协议"), getApiChoices(), draft.api);
|
|
190
|
-
if (choice) switchProviderDraftApiPreset(draft, choice.id);
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
if (fieldId === "openAIChatCompatibilityMode") {
|
|
194
|
-
const choice = await showOptionPicker(
|
|
195
|
-
ctx,
|
|
196
|
-
t("选择协议兼容"),
|
|
197
|
-
[
|
|
198
|
-
{ id: "standard", label: t("标准 — 保持 Pi 默认兼容判断") },
|
|
199
|
-
{ id: "compatible", label: t("兼容 — 强制 system role,适合忽略 developer 的中转") },
|
|
200
|
-
],
|
|
201
|
-
getOpenAIChatCompatibilityMode(draft),
|
|
202
|
-
);
|
|
203
|
-
if (choice) draft.openAIChatCompatibilityMode = choice.id as OpenAIChatCompatibilityMode;
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
if (fieldId === "openAIResponsesStreamCompletionMode") {
|
|
207
|
-
const choice = await showOptionPicker(
|
|
208
|
-
ctx,
|
|
209
|
-
t("选择流结束兼容"),
|
|
210
|
-
[
|
|
211
|
-
{ id: "standard", label: t("标准 — 等待上游正常关闭连接") },
|
|
212
|
-
{ id: "terminal-event", label: t("兼容 — 收到正式终态事件后主动结束") },
|
|
213
|
-
],
|
|
214
|
-
getOpenAIResponsesStreamCompletionMode(draft),
|
|
215
|
-
);
|
|
216
|
-
if (choice) draft.openAIResponsesStreamCompletionMode = choice.id as OpenAIResponsesStreamCompletionMode;
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
if (fieldId === "openAIResponsesAutoRecoveryEnabled") {
|
|
220
|
-
const choice = await showOptionPicker(
|
|
221
|
-
ctx,
|
|
222
|
-
t("跨资源自动恢复"),
|
|
223
|
-
[
|
|
224
|
-
{ id: "disabled", label: t("关闭 — 不检测或自动恢复跨资源状态错误") },
|
|
225
|
-
{ id: "enabled", label: t("开启 — 仅在指定错误后剥离旧 item ID 并重试一次,保留思维链") },
|
|
226
|
-
],
|
|
227
|
-
draft.openAIResponsesAutoRecoveryEnabled ? "enabled" : "disabled",
|
|
228
|
-
);
|
|
229
|
-
if (choice) draft.openAIResponsesAutoRecoveryEnabled = choice.id === "enabled";
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
if (fieldId === "authHeader") {
|
|
233
|
-
const choice = await showOptionPicker(
|
|
234
|
-
ctx,
|
|
235
|
-
t("认证头(API key 放在哪里)"),
|
|
236
|
-
[
|
|
237
|
-
{ id: "default", label: t("默认 — 交给协议 SDK / 接入默认行为") },
|
|
238
|
-
{ id: "bearer", label: t("Bearer — 强制 Authorization: Bearer <apiKey>") },
|
|
239
|
-
],
|
|
240
|
-
draft.authHeader ? "bearer" : "default",
|
|
241
|
-
);
|
|
242
|
-
if (choice) draft.authHeader = choice.id === "bearer";
|
|
243
|
-
return;
|
|
244
|
-
}
|
|
245
|
-
if (fieldId === "clientHeaderProfile") {
|
|
246
|
-
await editClientHeaderProfile(ctx, draft, requestHeaderProfiles);
|
|
247
|
-
return;
|
|
248
|
-
}
|
|
249
|
-
if (fieldId === "httpProxyEnabled") {
|
|
250
|
-
const choice = await showOptionPicker(
|
|
251
|
-
ctx,
|
|
252
|
-
t("本机代理(仅当前接入点)"),
|
|
253
|
-
[
|
|
254
|
-
{ id: "disabled", label: t("关闭 — 请求直连上游") },
|
|
255
|
-
{ id: "enabled", label: t("开启 — 通过 {url}", { url: redactUrlForDisplay(draft.httpProxyUrl || DEFAULT_PROVIDER_HTTP_PROXY_URL) }) },
|
|
256
|
-
],
|
|
257
|
-
draft.httpProxyEnabled ? "enabled" : "disabled",
|
|
258
|
-
);
|
|
259
|
-
if (!choice) return;
|
|
260
|
-
draft.httpProxyEnabled = choice.id === "enabled";
|
|
261
|
-
if (draft.httpProxyEnabled && !draft.httpProxyUrl.trim()) draft.httpProxyUrl = DEFAULT_PROVIDER_HTTP_PROXY_URL;
|
|
262
|
-
return;
|
|
263
|
-
}
|
|
264
|
-
if (fieldId === "providerId") {
|
|
265
|
-
const value = await ctx.ui.input(
|
|
266
|
-
t("接入 ID(必填,最多 48 个字符;仅字母、数字、点、下划线和连字符;当前:{current})", { current: draft.providerId || t("<空>") }),
|
|
267
|
-
draft.providerId,
|
|
268
|
-
);
|
|
269
|
-
if (value !== undefined) draft.providerId = value.trim();
|
|
270
|
-
return;
|
|
271
|
-
}
|
|
272
|
-
if (fieldId === "providerName") {
|
|
273
|
-
const value = await ctx.ui.input(t("名称(显示用,可留空;当前:{current})", { current: draft.providerName || t("<空>") }), draft.providerName);
|
|
274
|
-
if (value !== undefined) draft.providerName = value.trim();
|
|
275
|
-
return;
|
|
276
|
-
}
|
|
277
|
-
if (fieldId === "httpProxyUrl") {
|
|
278
|
-
const currentLabel = redactUrlForDisplay(draft.httpProxyUrl || DEFAULT_PROVIDER_HTTP_PROXY_URL);
|
|
279
|
-
const value = await ctx.ui.input(t("代理地址(http/https;当前:{current},留空保持原值)", { current: currentLabel }), "");
|
|
280
|
-
if (value?.trim()) draft.httpProxyUrl = value.trim();
|
|
281
|
-
return;
|
|
282
|
-
}
|
|
283
|
-
if (fieldId === "apiKey") {
|
|
284
|
-
const currentLabel = draft.apiKey ? maskSecret(draft.apiKey) : t("<空>");
|
|
285
|
-
const value = await ctx.ui.input(t("API key(可选;明文 / $ENV_VAR / !command;当前:{current},留空清除)", { current: currentLabel }), "");
|
|
286
|
-
if (value === undefined) return;
|
|
287
|
-
draft.apiKey = value.trim();
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
|
-
// [喵喵喵]: baseUrl 是唯一走通用文本输入的字段,显式列出才能保持 draft 的类型检查。
|
|
291
|
-
if (fieldId !== "baseUrl") return;
|
|
292
|
-
const value = await ctx.ui.input(t("Base URL(http/https)(当前:{current},留空保持原值)", { current: draft.baseUrl || t("<空>") }), draft.baseUrl);
|
|
293
|
-
if (value === undefined) return;
|
|
294
|
-
const trimmed = value.trim();
|
|
295
|
-
if (!trimmed) return;
|
|
296
|
-
// [喵喵喵]: 当场校验并归一化成 SDK 可直接使用的根地址;若输入有误通过通知友好提示,避免未捕获异常导致 TUI 闪退丢失草稿
|
|
297
|
-
try {
|
|
298
|
-
validateRequestBaseUrl(trimmed);
|
|
299
|
-
draft.baseUrl = resolveProviderDraftBaseUrl(draft.api, trimmed);
|
|
300
|
-
} catch (error) {
|
|
301
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
302
|
-
ctx.ui.notify(t("Base URL 格式错误:{error}", { error: message }), "warning");
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
export type ProviderEditOutcome =
|
|
307
|
-
| { action: "save"; draft: ProviderDraft }
|
|
308
|
-
| { action: "cancel" };
|
|
309
|
-
|
|
310
|
-
export async function editProvider(
|
|
311
|
-
ctx: ExtensionCommandContext,
|
|
312
|
-
draft: ProviderDraft,
|
|
313
|
-
titlePrefix: string,
|
|
314
|
-
requestHeaderProfiles: Record<string, StoredRequestHeaderProfile> = {},
|
|
315
|
-
): Promise<ProviderEditOutcome> {
|
|
316
|
-
const cursor: MenuCursor = { index: 0 };
|
|
317
|
-
while (true) {
|
|
318
|
-
// [喵喵喵]: 字段行的排版在开关切换后要原样重建,抽成函数避免两处写法飘移。
|
|
319
|
-
const toMenuRows = (fieldRows: FieldRow[]) => fieldRows.map((row) => ({
|
|
320
|
-
id: row.id,
|
|
321
|
-
label: `${padLabel(row.label, 16)}${row.adjustable ? markAdjustableValue(row.value) : row.value}`,
|
|
322
|
-
adjustable: row.adjustable,
|
|
323
|
-
}));
|
|
324
|
-
const rows = buildRows(draft, requestHeaderProfiles);
|
|
325
|
-
const menuRows = toMenuRows(rows);
|
|
326
|
-
const getSummaryLines = (): string[] => {
|
|
327
|
-
const summaryLines = [
|
|
328
|
-
`API ${formatApiShort(draft.api)} · ${t("请求头")} ${describeProfile(draft.clientHeaderProfile, draft.api, draft.requestHeaderProfileId, requestHeaderProfiles)}`,
|
|
329
|
-
t("接入 ID 必填,且不能与已有或 pi 内置接入重复"),
|
|
330
|
-
t("Ctrl+S 保存并同步 models.json;不切换当前会话模型"),
|
|
331
|
-
];
|
|
332
|
-
if (draft.api === "openai-completions") {
|
|
333
|
-
summaryLines.push(getOpenAIChatCompatibilityModeHint(getOpenAIChatCompatibilityMode(draft)));
|
|
334
|
-
}
|
|
335
|
-
if (draft.api === "openai-responses") {
|
|
336
|
-
summaryLines.push(getOpenAIResponsesStreamCompletionModeHint(getOpenAIResponsesStreamCompletionMode(draft)));
|
|
337
|
-
summaryLines.push(draft.openAIResponsesAutoRecoveryEnabled
|
|
338
|
-
? t("跨资源自动恢复已开启:仅在指定错误后剥离旧 item ID 并重试一次;完整保留思维链,每次提示结果。")
|
|
339
|
-
: t("跨资源自动恢复已关闭:不检测或自动处理资源归属、item ID 与加密状态错误。"));
|
|
340
|
-
}
|
|
341
|
-
return summaryLines;
|
|
342
|
-
};
|
|
343
|
-
const action = await showPersistentFormMenu(
|
|
344
|
-
ctx,
|
|
345
|
-
titlePrefix,
|
|
346
|
-
"",
|
|
347
|
-
menuRows,
|
|
348
|
-
cursor,
|
|
349
|
-
{
|
|
350
|
-
getSummaryLines,
|
|
351
|
-
onAdjust: (id, direction) => {
|
|
352
|
-
if (!applyHorizontalToggle(draft, id, direction)) return undefined;
|
|
353
|
-
return toMenuRows(buildRows(draft, requestHeaderProfiles));
|
|
354
|
-
},
|
|
355
|
-
hints: [
|
|
356
|
-
{ key: "↑↓", label: t("选择") },
|
|
357
|
-
{ key: "←→", label: t("切换选项") },
|
|
358
|
-
{ key: "Enter", label: t("编辑") },
|
|
359
|
-
{ key: "Ctrl+S", label: t("保存并同步") },
|
|
360
|
-
{ key: "Esc", label: t("返回") },
|
|
361
|
-
],
|
|
362
|
-
},
|
|
363
|
-
);
|
|
364
|
-
if (action.type === "cancel") return { action: "cancel" };
|
|
365
|
-
if (action.type === "save") return { action: "save", draft };
|
|
366
|
-
await editField(ctx, draft, action.id, requestHeaderProfiles);
|
|
367
|
-
}
|
|
368
|
-
}
|