pi-model-manager 0.4.8 → 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.
@@ -35,10 +35,11 @@ import {
35
35
  readMetadataStateSnapshot,
36
36
  serializeMetadataState,
37
37
  type MetadataDocument,
38
+ type MetadataStateSnapshot,
38
39
  } from "./state-metadata-store.ts";
39
- import { getClientHeadersForProfile, resolveClientHeaderProfile } from "./presets/client-headers.ts";
40
- import { buildStateDocumentFromSources, tryReadStateSnapshot, type StateSourceSnapshot } from "./state-store.ts";
41
- import type { ApiKind, StateDocument } from "./types.ts";
40
+ import { stripManagedClientHeaders } from "./presets/client-headers.ts";
41
+ import { buildStateDocumentFromSources, tryReadStateSnapshot } from "./state-store.ts";
42
+ import type { StateDocument } from "./types.ts";
42
43
 
43
44
  interface PreparedConfigurationChange {
44
45
  document: StateDocument;
@@ -48,6 +49,11 @@ interface PreparedConfigurationChange {
48
49
 
49
50
  export type PrepareConfigurationChange = (latest: StateDocument) => PreparedConfigurationChange;
50
51
 
52
+ export interface ConfigurationCommitResult {
53
+ document: StateDocument;
54
+ warnings: string[];
55
+ }
56
+
51
57
  interface FileTransition {
52
58
  oldSource: string | null;
53
59
  oldHash: string;
@@ -184,8 +190,8 @@ async function writeConfigurationTransaction(
184
190
  assertSnapshotStillCurrent(MODELS_JSON_PATH, modelsSnapshot.contentHash),
185
191
  assertSnapshotStillCurrent(STATE_PATH, metadataSnapshot.contentHash),
186
192
  ]);
187
- if (metadataSnapshot.metadata.version < 5) {
188
- const backupPath = join(STATE_DIR, `base-url-v5-${hashTextContent(journal.modelsJson.oldHash + journal.metadataState.oldHash).slice(0, 16)}.json`);
193
+ if (needsConfigurationMigration(metadataSnapshot)) {
194
+ const backupPath = join(STATE_DIR, `configuration-v6-${hashTextContent(journal.modelsJson.oldHash + journal.metadataState.oldHash).slice(0, 16)}.json`);
189
195
  const backup = await readStableTextFileSnapshot(backupPath);
190
196
  if (backup.source === undefined) await atomicWriteText(backupPath, stringifyJson(journal), SECURE_FILE_MODE);
191
197
  else {
@@ -213,7 +219,7 @@ type ModelsDocumentMutation = (
213
219
  change: PreparedConfigurationChange,
214
220
  ) => ModelsJsonDocument;
215
221
 
216
- function migrateGeneratedClaudeCodeBetas(
222
+ function removePersistedBuiltinHeaders(
217
223
  source: ModelsJsonDocument,
218
224
  state: StateDocument,
219
225
  metadata: MetadataDocument,
@@ -221,20 +227,16 @@ function migrateGeneratedClaudeCodeBetas(
221
227
  let result = source;
222
228
  for (const [providerId, provider] of Object.entries(state.providers)) {
223
229
  const entry = source.providers[providerId];
224
- if (!provider.managed || !entry?.models) continue;
230
+ if (!provider.managed || provider.clientHeaderProfile === "custom" || !entry?.models) continue;
225
231
  let changed = false;
226
232
  const models = entry.models.map((model) => {
227
- if (resolveClientHeaderProfile(provider.clientHeaderProfile, (model.api ?? provider.api) as ApiKind) !== "claude-code") return model;
228
233
  const generated = metadata.models[`${providerId}/${model.id}`]?.generatedClientHeaders;
229
- const beta = Object.entries(generated ?? {}).find(([name]) => name.toLowerCase() === "anthropic-beta");
230
- if (!beta) return model;
231
- const owned = Object.entries(model.headers ?? {}).filter(([name, value]) => name.toLowerCase() === "anthropic-beta" && value === beta[1]);
232
- if (owned.length === 0) return model;
233
- // [喵喵喵]: 只删除来源快照证明仍属插件的旧值;不按 beta 内容猜测归属,不改写模型其它字段。
234
- const headers = { ...model.headers };
235
- for (const [name] of owned) delete headers[name];
234
+ if (!generated || !model.headers) return model;
235
+ // [喵喵喵]: 仅删除来源记录证明仍属插件的值;同名用户改写和没有记录的字段均保留。
236
+ const headers = stripManagedClientHeaders(model.headers, generated);
237
+ if (Object.keys(headers ?? {}).length === Object.keys(model.headers).length) return model;
236
238
  const next = { ...model };
237
- if (Object.keys(headers).length > 0) next.headers = headers;
239
+ if (headers) next.headers = headers;
238
240
  else delete next.headers;
239
241
  changed = true;
240
242
  return next;
@@ -244,10 +246,6 @@ function migrateGeneratedClaudeCodeBetas(
244
246
  return result;
245
247
  }
246
248
 
247
- function hasCapturedClaudeCodeBeta(state: StateDocument): boolean {
248
- return Object.keys(state.clientHeaderCaptures["claude-code"]?.headers ?? {}).some((name) => name.toLowerCase() === "anthropic-beta");
249
- }
250
-
251
249
  async function persistConfigurationInsideLock(
252
250
  prepare: PrepareConfigurationChange,
253
251
  mutateModels: ModelsDocumentMutation,
@@ -260,15 +258,6 @@ async function persistConfigurationInsideLock(
260
258
  readMetadataStateSnapshot(),
261
259
  ]);
262
260
  const latest = await buildStateDocumentFromSources(modelsSnapshot.document, metadataSnapshot);
263
- if (hasCapturedClaudeCodeBeta(latest)) {
264
- latest.clientHeaderCaptures = {
265
- ...latest.clientHeaderCaptures,
266
- "claude-code": {
267
- ...latest.clientHeaderCaptures["claude-code"]!,
268
- headers: getClientHeadersForProfile("claude-code", "anthropic-messages", {}, latest.clientHeaderCaptures)!,
269
- },
270
- };
271
- }
272
261
  const sourceWithOwnershipMarkers = metadataSnapshot.requirePluginManagedProviderMarker
273
262
  ? modelsSnapshot.document
274
263
  : markManagedProvidersInDoc(modelsSnapshot.document, latest.managedProviderIds);
@@ -278,7 +267,7 @@ async function persistConfigurationInsideLock(
278
267
  [],
279
268
  Object.keys(metadataSnapshot.legacyProviders),
280
269
  );
281
- const sourceWithCurrentHeaders = migrateGeneratedClaudeCodeBetas(sourceWithLegacyProviders, latest, metadataSnapshot.metadata);
270
+ const sourceWithCurrentHeaders = removePersistedBuiltinHeaders(sourceWithLegacyProviders, latest, metadataSnapshot.metadata);
282
271
  const migratedSource = metadataSnapshot.metadata.version < 5
283
272
  ? migrateManagedBaseUrls(latest, sourceWithCurrentHeaders)
284
273
  : sourceWithCurrentHeaders;
@@ -304,38 +293,35 @@ async function persistConfigurationInsideLock(
304
293
  return change.document;
305
294
  }
306
295
 
307
- async function needsConfigurationMigration(snapshot: StateSourceSnapshot): Promise<boolean> {
308
- if (snapshot.metadata.metadata.version < 5) return true;
309
- const state = await buildStateDocumentFromSources(snapshot.models.document, snapshot.metadata);
310
- if (hasCapturedClaudeCodeBeta(state)
311
- || migrateGeneratedClaudeCodeBetas(snapshot.models.document, state, snapshot.metadata.metadata) !== snapshot.models.document) return true;
312
- return Object.entries(state.providers).some(([providerId, provider]) => provider.managed
313
- && provider.models.some((model) => snapshot.metadata.metadata.models[`${providerId}/${model.id}`]?.generatedClientHeaders === undefined));
296
+ function needsConfigurationMigration(snapshot: MetadataStateSnapshot): boolean {
297
+ const metadata = snapshot.metadata;
298
+ return metadata.version < 6 || snapshot.hasLegacyClientHeaderCaptures
299
+ || Object.entries(metadata.models).some(([fullId, model]) => model.generatedClientHeaders !== undefined
300
+ && metadata.providers[fullId.slice(0, fullId.indexOf("/"))]?.clientHeaderProfile !== "custom");
314
301
  }
315
302
 
316
- /** 在 catalog 注册前升级地址语义、清理自动画像 beta,并初始化缺少的生成头快照。 */
317
- export async function migrateManagedEndpointConfiguration(): Promise<boolean> {
303
+ /** 在 catalog 注册前一次性升级地址语义,并移除有来源记录的内置头副本。 */
304
+ export async function migrateManagedConfiguration(): Promise<boolean> {
318
305
  const snapshot = await tryReadStateSnapshot();
319
- if (snapshot && !(await needsConfigurationMigration(snapshot))) return false;
306
+ if (snapshot && !needsConfigurationMigration(snapshot.metadata)) return false;
320
307
  return withConfigurationLock(async () => {
321
308
  await recoverPendingConfigurationTransactionInsideLock();
322
309
  // [喵喵喵]: 锁外快照只用于免写判断;等待锁期间配置可能已被其它会话迁移,写入前须重新判定。
323
- const [models, metadata] = await Promise.all([readModelsJsonSnapshot(), readMetadataStateSnapshot()]);
324
- if (!(await needsConfigurationMigration({ models, metadata }))) return false;
325
- const migrateEndpoints = metadata.metadata.version < 5;
310
+ const metadata = await readMetadataStateSnapshot();
311
+ if (!needsConfigurationMigration(metadata)) return false;
326
312
  await persistConfigurationInsideLock(
327
313
  (document) => ({ document, changedProviderIds: [], removedProviderIds: [] }),
328
314
  (source) => source,
329
315
  );
330
316
  invalidateStateCache();
331
- return migrateEndpoints;
317
+ return true;
332
318
  });
333
319
  }
334
320
 
335
321
  async function refreshRegistryAfterPersistence(
336
322
  ctx: RegistryRefreshContext,
337
323
  persist: () => Promise<StateDocument>,
338
- ): Promise<StateDocument> {
324
+ ): Promise<ConfigurationCommitResult> {
339
325
  let document: StateDocument;
340
326
  try {
341
327
  document = await withConfigurationLock(persist);
@@ -343,18 +329,19 @@ async function refreshRegistryAfterPersistence(
343
329
  } catch (error) {
344
330
  throw new Error(t("models.json/state.json 未完整保存:{error}", { error: formatUnknownError(error) }));
345
331
  }
332
+ const warnings: string[] = [];
346
333
  try {
347
334
  await ctx.modelRegistry.refresh();
348
335
  } catch (error) {
349
- throw new Error(t("models.json/state.json 已写入,但当前会话 registry 重载失败:{error}。可执行 /reload 重试。", { error: formatUnknownError(error) }));
336
+ warnings.push(t("models.json/state.json 已写入,但当前会话 registry 重载失败:{error}。可执行 /reload 重试。", { error: formatUnknownError(error) }));
350
337
  }
351
- return document;
338
+ return { document, warnings };
352
339
  }
353
340
 
354
341
  export async function persistManagedConfiguration(
355
342
  ctx: RegistryRefreshContext,
356
343
  prepare: PrepareConfigurationChange,
357
- ): Promise<StateDocument> {
344
+ ): Promise<ConfigurationCommitResult> {
358
345
  return refreshRegistryAfterPersistence(ctx, () => persistConfigurationInsideLock(
359
346
  prepare,
360
347
  (source, change) => buildSynchronizedModelsDocument(
@@ -371,7 +358,7 @@ export async function persistProviderRenameConfiguration(
371
358
  prepare: PrepareConfigurationChange,
372
359
  oldProviderId: string,
373
360
  newProviderId: string,
374
- ): Promise<StateDocument> {
361
+ ): Promise<ConfigurationCommitResult> {
375
362
  return refreshRegistryAfterPersistence(ctx, () => persistConfigurationInsideLock(
376
363
  prepare,
377
364
  (source, change) => buildSynchronizedModelsDocument(
@@ -388,7 +375,7 @@ export async function persistModelConfiguration(
388
375
  prepare: PrepareConfigurationChange,
389
376
  providerId: string,
390
377
  modelId: string,
391
- ): Promise<StateDocument> {
378
+ ): Promise<ConfigurationCommitResult> {
392
379
  return refreshRegistryAfterPersistence(ctx, () => persistConfigurationInsideLock(
393
380
  prepare,
394
381
  (source, change) => buildModelsDocumentWithSynchronizedModel(
@@ -407,7 +394,7 @@ export async function persistModelRenameConfiguration(
407
394
  providerId: string,
408
395
  oldModelId: string,
409
396
  newModelId: string,
410
- ): Promise<StateDocument> {
397
+ ): Promise<ConfigurationCommitResult> {
411
398
  return refreshRegistryAfterPersistence(ctx, () => persistConfigurationInsideLock(
412
399
  prepare,
413
400
  (source, change) => buildModelsDocumentWithSynchronizedModel(
@@ -426,7 +413,7 @@ export async function persistModelDeletionConfiguration(
426
413
  prepare: PrepareConfigurationChange,
427
414
  providerId: string,
428
415
  modelId: string,
429
- ): Promise<StateDocument> {
416
+ ): Promise<ConfigurationCommitResult> {
430
417
  return refreshRegistryAfterPersistence(ctx, () => persistConfigurationInsideLock(
431
418
  prepare,
432
419
  (source, change) => buildModelsDocumentWithoutModel(change.document, source, providerId, modelId),
@@ -7,22 +7,11 @@ import { persistManagedConfiguration } from "./configuration-persistence.ts";
7
7
  import { t } from "./i18n.ts";
8
8
  import { formatUnknownError } from "./common.ts";
9
9
  import { reconcileProvider } from "./provider-registrar.ts";
10
- import { deleteRequestHeaderProfileFromDocument, upsertRequestHeaderProfileInDocument, validateRequestHeaderProfileDraft } from "./state-document.ts";
11
- import type { RequestHeaderProfileDraft, StateDocument, StoredProvider } from "./types.ts";
10
+ import { deleteRequestHeaderProfileFromDocument, findRequestHeaderProfileProviders, upsertRequestHeaderProfileInDocument, validateRequestHeaderProfileDraft } from "./state-document.ts";
11
+ import type { ConfigurationChangeResult, RequestHeaderProfileDraft, StateDocument } from "./types.ts";
12
12
 
13
- function providerReferencesProfile(provider: StoredProvider, profileId: string): boolean {
14
- return provider.requestHeaderProfileId === profileId
15
- || provider.models.some((model) => model.requestHeaderProfileId === profileId);
16
- }
17
-
18
- function findProfileProviderIds(
19
- document: StateDocument,
20
- profileIds: string[],
21
- ): string[] {
22
- const ids = new Set(profileIds);
23
- return Object.entries(document.providers)
24
- .filter(([, provider]) => provider.managed && [...ids].some((profileId) => providerReferencesProfile(provider, profileId)))
25
- .map(([providerId]) => providerId);
13
+ function findProfileProviderIds(document: StateDocument, profileIds: string[]): string[] {
14
+ return [...new Set(profileIds.flatMap((id) => findRequestHeaderProfileProviders(document, id)))];
26
15
  }
27
16
 
28
17
  async function refreshProfileProviders(pi: ExtensionAPI, document: StateDocument, providerIds: string[]): Promise<string[]> {
@@ -31,7 +20,7 @@ async function refreshProfileProviders(pi: ExtensionAPI, document: StateDocument
31
20
  const provider = document.providers[providerId];
32
21
  if (!provider) continue;
33
22
  try {
34
- await reconcileProvider(pi, providerId, provider, document.requestHeaderProfiles, document.clientHeaderCaptures);
23
+ await reconcileProvider(pi, providerId, provider, document.requestHeaderProfiles);
35
24
  } catch (error) {
36
25
  warnings.push(`${providerId}: ${formatUnknownError(error)}`);
37
26
  }
@@ -39,28 +28,15 @@ async function refreshProfileProviders(pi: ExtensionAPI, document: StateDocument
39
28
  return warnings;
40
29
  }
41
30
 
42
- function notifyHeaderProfileRefresh(
43
- ctx: ExtensionCommandContext,
44
- successMessage: string,
45
- warnings: string[],
46
- ): void {
47
- if (warnings.length === 0) {
48
- ctx.ui.notify(successMessage, "info");
49
- return;
50
- }
51
- ctx.ui.notify(t("{successMessage},但以下接入未能刷新,已保留上一版 runtime:\n- {warnings}", { successMessage, warnings: warnings.join("\n- ") }), "warning");
52
- }
53
-
54
31
  export async function saveRequestHeaderProfileConfiguration(
55
32
  pi: ExtensionAPI,
56
33
  ctx: ExtensionCommandContext,
57
- _state: StateDocument,
58
34
  draft: RequestHeaderProfileDraft,
59
35
  oldProfileId: string | undefined,
60
- ): Promise<void> {
36
+ ): Promise<ConfigurationChangeResult> {
61
37
  const profileId = draft.profileId.trim();
62
38
  let affectedProviderIds: string[] = [];
63
- const nextState = await persistManagedConfiguration(ctx, (latest) => {
39
+ const result = await persistManagedConfiguration(ctx, (latest) => {
64
40
  if (oldProfileId && !latest.requestHeaderProfiles[oldProfileId]) {
65
41
  throw new Error(t("请求头不存在:{profileId}", { profileId: oldProfileId }));
66
42
  }
@@ -73,18 +49,17 @@ export async function saveRequestHeaderProfileConfiguration(
73
49
  removedProviderIds: [],
74
50
  };
75
51
  });
76
- const warnings = await refreshProfileProviders(pi, nextState, affectedProviderIds);
77
- notifyHeaderProfileRefresh(ctx, t("已保存请求头 {profileId}", { profileId: draft.profileId.trim() }), warnings);
52
+ result.warnings.push(...await refreshProfileProviders(pi, result.document, affectedProviderIds));
53
+ return { ...result, messages: [t("已保存请求头 {profileId}", { profileId })] };
78
54
  }
79
55
 
80
56
  export async function deleteRequestHeaderProfileConfiguration(
81
57
  pi: ExtensionAPI,
82
58
  ctx: ExtensionCommandContext,
83
- _state: StateDocument,
84
59
  profileId: string,
85
- ): Promise<void> {
60
+ ): Promise<ConfigurationChangeResult> {
86
61
  let affectedProviderIds: string[] = [];
87
- const nextState = await persistManagedConfiguration(ctx, (latest) => {
62
+ const result = await persistManagedConfiguration(ctx, (latest) => {
88
63
  affectedProviderIds = findProfileProviderIds(latest, [profileId]);
89
64
  return {
90
65
  document: deleteRequestHeaderProfileFromDocument(latest, profileId),
@@ -92,6 +67,6 @@ export async function deleteRequestHeaderProfileConfiguration(
92
67
  removedProviderIds: [],
93
68
  };
94
69
  });
95
- const warnings = await refreshProfileProviders(pi, nextState, affectedProviderIds);
96
- notifyHeaderProfileRefresh(ctx, t("已删除请求头 {profileId}", { profileId }), warnings);
70
+ result.warnings.push(...await refreshProfileProviders(pi, result.document, affectedProviderIds));
71
+ return { ...result, messages: [t("已删除请求头 {profileId}", { profileId })] };
97
72
  }
package/i18n.ts CHANGED
@@ -6,13 +6,13 @@ export const DEFAULT_UI_LANGUAGE: UiLanguage = "zh-CN";
6
6
 
7
7
  const ENGLISH_MESSAGES = {
8
8
  "Base URL 必须使用 http 或 https": "Base URL must use http or https",
9
- "Base URL 格式错误:{error}": "Invalid Base URL: {error}",
10
9
  "Base URL 不支持查询参数(?)或片段(#);请填写 API 根地址": "Base URL cannot contain query parameters (?) or fragments (#); enter the API root URL",
11
10
  "Base URL 不支持内嵌认证;请使用 API key 或请求头配置": "Base URL cannot contain credentials; use the API key or header configuration",
12
11
  "请求模型不属于当前接入配置:{modelId}": "Request model is not part of the current provider configuration: {modelId}",
13
12
  "该协议尚不支持接入级代理:{api}": "Provider-level proxy is not supported for this API: {api}",
14
13
  "Anthropic 请求路径与当前适配契约不符": "Anthropic request path does not match the transport contract",
15
14
  "无法构建接入:{providerId}": "Failed to construct provider: {providerId}",
15
+ "接入已移除或不再由插件管理:{providerId}": "Provider was removed or is no longer managed by the plugin: {providerId}",
16
16
  "请求配置读取失败,本次使用原始 payload": "Failed to read request configuration; using the original payload",
17
17
  "认证失败,请检查 API key 和认证头": "Authentication failed; check the API key and authentication headers",
18
18
  "模型列表接口不存在,可继续手动添加模型": "The model list endpoint is unavailable; models can still be added manually",
@@ -22,49 +22,28 @@ const ENGLISH_MESSAGES = {
22
22
  "语言 / Language": "Language",
23
23
  "简体中文": "Simplified Chinese",
24
24
  "English": "English",
25
- "语言已切换为 {language}": "Language switched to {language}",
26
- "语言设置保存失败:{error}": "Failed to save language setting: {error}",
27
25
  "读取语言设置失败,已使用简体中文:{error}": "Failed to load the language setting; using Simplified Chinese: {error}",
28
26
  "语言设置根节点必须是对象": "The language settings root must be an object",
29
27
  "不支持的语言设置版本:{version}": "Unsupported language settings version: {version}",
30
28
  "不支持的界面语言:{language}": "Unsupported interface language: {language}",
31
29
 
32
- "过滤:": "Filter: ",
33
- "搜索:": "Search: ",
34
- "<输入关键词>": "<type keywords>",
35
- "保留过滤": "Keep filter",
36
30
  "清空搜索": "Clear search",
37
- "继续输入": "Continue typing",
38
- "清空过滤": "Clear filter",
39
31
  "搜索": "Search",
40
- "无匹配项:{query}": "No matches: {query}",
41
32
  "暂无条目": "No entries",
42
- "● 当前": "● current",
43
- "移动": "Move",
44
33
  "选择": "Select",
45
34
  "返回": "Back",
46
35
  "进入": "Open",
47
36
  "编辑": "Edit",
48
- "退出": "Exit",
49
- "切换选项": "Toggle",
50
- "保存并同步": "Save & sync",
51
- "保存并启用": "Save & enable",
52
37
 
53
38
  "<未填写>": "<not set>",
54
- "<必填>": "<required>",
55
39
  "<空>": "<empty>",
56
- "<无模型>": "<no models>",
57
- "<未选择>": "<not selected>",
58
- "<未配置>": "<not configured>",
59
40
  "默认": "Default",
60
41
  "开启": "On",
61
42
  "关闭": "Off",
62
- "关闭时不使用": "Not used while off",
63
43
  "自动推荐": "Recommended",
64
44
  "不添加": "Disabled",
65
45
  "自定义请求头": "Custom headers",
66
46
  "内联自定义请求头({count}项)": "Inline custom headers ({count})",
67
- "自定义:{id} — {name}": "Custom: {id} — {name}",
68
47
  "自定义请求头(未选择)": "Custom headers (not selected)",
69
48
  "自定义请求头缺失:{id}": "Missing custom header profile: {id}",
70
49
 
@@ -73,7 +52,6 @@ const ENGLISH_MESSAGES = {
73
52
  "请求头": "Headers",
74
53
  "代理": "Proxy",
75
54
  "认证": "Auth",
76
- "状态": "Status",
77
55
  "模型 ID": "Model ID",
78
56
  "显示名": "Display name",
79
57
  "输入": "Input",
@@ -92,41 +70,18 @@ const ENGLISH_MESSAGES = {
92
70
  "协议兼容": "Protocol compatibility",
93
71
  "标准 · Pi 默认": "Standard · Pi default",
94
72
  "兼容 · system": "Compatible · system",
95
- "选择协议兼容": "Select protocol compatibility",
96
- "标准 — 保持 Pi 默认兼容判断": "Standard — keep Pi's default compatibility detection",
97
- "兼容 — 强制 system role,适合忽略 developer 的中转": "Compatible — force the system role for relays that ignore developer",
98
73
  "标准模式:保持 Pi 默认兼容判断。": "Standard mode: keep Pi's default compatibility detection.",
99
74
  "兼容模式:系统提示词强制使用 system role,适合忽略 developer 的中转。": "Compatibility mode: the system prompt always uses the system role for relays that ignore developer.",
100
75
  "流结束兼容": "Stream completion",
101
76
  "兼容 · 终态即结束": "Compatible · end on terminal event",
102
77
  "标准 · 等待连接关闭": "Standard · wait for connection close",
103
- "选择流结束兼容": "Select stream completion mode",
104
- "标准 — 等待上游正常关闭连接": "Standard — wait for upstream to close the connection",
105
- "兼容 — 收到正式终态事件后主动结束": "Compatible — finish after receiving a formal terminal event",
106
78
  "兼容模式:正式终态事件已转交后主动结束,不等待上游关闭连接。": "Compatibility mode: finish after forwarding the formal terminal event without waiting for upstream to close.",
107
79
  "标准模式:等待上游正常结束流。若回复完成后长期卡住,可启用兼容模式。": "Standard mode: wait for upstream to finish the stream normally. Enable compatibility mode if completed replies remain stuck.",
108
80
  "未知 Responses 流结束模式:{value}": "Unknown Responses stream completion mode: {value}",
109
81
  "跨资源自动恢复": "State recovery",
110
- "关闭 — 不检测或自动恢复跨资源状态错误": "Off — do not detect or recover cross-resource state errors",
111
82
  "开启 — 仅在指定错误后剥离旧 item ID 并重试一次,保留思维链": "On — strip old item IDs and retry once only for matching errors; preserve reasoning",
112
- "跨资源自动恢复已开启:仅在指定错误后剥离旧 item ID 并重试一次;完整保留思维链,每次提示结果。": "State recovery is on: strip old item IDs and retry matching errors once, preserve reasoning in full, and report each result.",
113
- "跨资源自动恢复已关闭:不检测或自动处理资源归属、item ID 与加密状态错误。": "State recovery is off: resource ownership, item ID, and encrypted state errors are not detected or recovered.",
114
- "接入 ID 必填,且不能与已有或 pi 内置接入重复": "Provider ID is required and must not duplicate an existing or built-in Pi provider",
115
- "Ctrl+S 保存并同步 models.json;不切换当前会话模型": "Ctrl+S saves and syncs models.json without switching the current session model",
116
- "选择 API 协议": "Select API protocol",
117
- "认证头(API key 放在哪里)": "Auth header (where the API key is sent)",
118
83
  "默认 — 交给协议 SDK / 接入默认行为": "Default — use the protocol SDK/provider behavior",
119
84
  "Bearer — 强制 Authorization: Bearer <apiKey>": "Bearer — force Authorization: Bearer <apiKey>",
120
- "本机代理(仅当前接入点)": "Local proxy (this provider only)",
121
- "关闭 — 请求直连上游": "Off — connect directly to upstream",
122
- "开启 — 通过 {url}": "On — route through {url}",
123
- "接入 ID(必填,最多 48 个字符;仅字母、数字、点、下划线和连字符;当前:{current})": "Provider ID (required, max 48 characters; letters, digits, dots, underscores, and hyphens only; current: {current})",
124
- "名称(显示用,可留空;当前:{current})": "Name (optional display label; current: {current})",
125
- "代理地址(http/https;当前:{current},留空保持原值)": "Proxy URL (http/https; current: {current}; leave blank to keep it)",
126
- "API key(可选;明文 / $ENV_VAR / !command;当前:{current},留空清除)": "API key (optional; literal / $ENV_VAR / !command; current: {current}; leave blank to clear)",
127
- "Base URL(http/https)(当前:{current},留空保持原值)": "Base URL (http/https; current: {current}; leave blank to keep it)",
128
-
129
- "重新拉取": "Refresh list",
130
85
  "上游模型列表": "Upstream model list",
131
86
  "显示名称": "Display name",
132
87
  "默认 = 模型 ID": "Default = model ID",
@@ -136,114 +91,53 @@ const ENGLISH_MESSAGES = {
136
91
  "开启 · 新版协议": "On · current protocol",
137
92
  "关闭 · Legacy": "Off · Legacy",
138
93
  "标准": "Standard",
139
- "正在拉取模型列表,总计最多 10 秒…": "Fetching the model list (10 seconds maximum)…",
140
94
  "拉取失败:{error}": "Fetch failed: {error}",
141
- "手动输入模型 ID(当前:{current})": "Enter a model ID manually (current: {current})",
142
95
  "上游返回空列表": "Upstream returned an empty list",
143
- "选择模型 ID(共 {count} 个)": "Select a model ID ({count} available)",
144
- "{label}(当前:{current},留空保持原值)": "{label} (current: {current}; leave blank to keep it)",
145
96
  "{label} 必须是正整数": "{label} must be a positive integer",
146
- "模型 ID(当前:{current},传给上游 API 的模型字段)": "Model ID (current: {current}; sent as the upstream API model field)",
147
- "显示名称(当前:{current},可空默认用模型 ID;输入空格清空)": "Display name (current: {current}; blank uses the model ID; enter a space to clear)",
148
- "关闭 — 仅文本输入": "Off — text input only",
149
- "开启 — 文本 + 图片输入": "On — text and image input",
150
- "关闭 — 不发送模型推理参数": "Off — do not send reasoning parameters",
151
- "开启 — 启用模型推理参数": "On — enable reasoning parameters",
152
97
  "开启:新版模型,发送 thinking.type=adaptive 和 output_config.effort": "On: current models; send thinking.type=adaptive and output_config.effort",
153
98
  "关闭:旧版接口,发送 thinking.type=enabled 和 budget_tokens": "Off: legacy API; send thinking.type=enabled and budget_tokens",
154
99
  "标准 — 不发送 service_tier": "Standard — do not send service_tier",
155
100
  "Fast — service_tier=priority,可能产生额外费用": "Fast — service_tier=priority; extra charges may apply",
156
101
  "Ultrafast — service_tier=ultrafast,需上游支持且可能产生额外费用": "Ultrafast — service_tier=ultrafast; requires upstream support and may cost extra",
157
- "接入 {providerId} · API {api}": "Provider {providerId} · API {api}",
158
- "Ctrl+S 保存并启用模型;不切换当前会话模型": "Ctrl+S saves and enables the model without switching the current session model",
159
-
160
- "页码 0 / 0": "Page 0 / 0",
161
- "页码 {page} / {pages}": "Page {page} / {pages}",
162
- "搜索: ": "Search: ",
163
- "<直接输入搜索>": "<type to search>",
164
- "匹配 {matched} / {total} · {page}": "Matches {matched} / {total} · {page}",
165
- "没有匹配模型;Backspace 删除搜索词,Esc 返回后可手动输入。": "No matching models. Use Backspace to edit the search, or Esc to enter an ID manually.",
166
- " ● 当前": " ● current",
167
- "↑↓ 选择 · ←→/PgUp/PgDn 翻页 · 输入搜索 · Backspace 删除 · Enter 确认 · Esc 取消": "↑↓ select · ←→/PgUp/PgDn page · type to search · Backspace delete · Enter confirm · Esc cancel",
168
-
169
102
  "OpenAI Responses · 标准 instructions/input wire": "OpenAI Responses · standard instructions/input wire",
170
103
  "OpenAI Chat · 传统 chat/completions 兼容": "OpenAI Chat · legacy chat/completions compatibility",
171
104
  "Anthropic Messages · Claude / Claude Code 兼容": "Anthropic Messages · Claude / Claude Code compatibility",
172
105
  "Google Gemini · Gemini 原生 API": "Google Gemini · native Gemini API",
173
106
 
174
107
  "请确认改动": "Confirm changes",
175
- "{warnings}\n\n继续保存?": "{warnings}\n\nContinue saving?",
176
- "{title}:\n{errors}": "{title}:\n{errors}",
177
- "接入配置无效": "Invalid provider configuration",
178
- "模型配置无效": "Invalid model configuration",
179
108
  "保存失败:{error}": "Save failed: {error}",
180
- "删除失败:{error}": "Delete failed: {error}",
181
109
  "删除接入 {providerId}": "Delete provider {providerId}",
182
110
  "将删除 {name} 下全部 {count} 个模型。": "Delete {name} and all of its models ({count}).",
183
111
  "删除模型 {fullId}": "Delete model {fullId}",
184
- "这是该接入下最后一个模型;删除后接入也会从 models.json 中移除。": "This is the provider's last model; deleting it will also remove the provider from models.json.",
185
112
  "只删除该模型,接入保留。": "Delete only this model and keep the provider.",
186
113
  "模型不存在:{fullId}": "Model not found: {fullId}",
187
- "编辑模型 {fullId}": "Edit model {fullId}",
188
114
  "接入配置已不存在:{providerId}": "Provider configuration no longer exists: {providerId}",
189
115
  "编辑模型": "Edit model",
190
116
  "添加模型": "Add model",
191
117
  "编辑接入": "Edit provider",
192
- "删除模型": "Delete model",
193
- "暂无模型;按 a 添加第一个模型": "No models. Press A to add the first model.",
194
- "添加模型到 {providerId}": "Add model to {providerId}",
195
- "编辑接入 {providerId}": "Edit provider {providerId}",
196
- "没有可删除的模型;删除接入请返回上一级按 d。": "There are no models to delete. Return to the previous menu and press D to delete the provider.",
197
- "新建接入配置": "New provider configuration",
198
- "请继续添加第一个模型;取消模型编辑则不会创建该接入。": "Add the first model next. Cancelling the model editor will leave the provider uncreated.",
199
118
  "新建接入": "New provider",
200
- "删除接入": "Delete provider",
201
- "{providers} 接入 · {models} 模型 · {captures} 内置抓包 · {profiles} 自定义请求头": "Providers: {providers} · Models: {models} · Built-in captures: {captures} · Custom headers: {profiles}",
202
119
  "请求头管理": "Headers",
203
- "暂无自定义接入;按 n 新建": "No custom providers. Press N to create one.",
204
- "没有可删除的接入。": "There are no providers to delete.",
205
120
 
206
- "OpenAI 兼容端点使用的终端 Codex TUI 请求头。": "Terminal Codex TUI headers for OpenAI-compatible endpoints.",
121
+ "OpenAI 兼容端点使用的 Codex Rust CLI 请求头。": "Codex Rust CLI headers for OpenAI-compatible endpoints.",
207
122
  "Anthropic 兼容端点常用的 ClaudeCode 请求头。": "Common ClaudeCode headers for Anthropic-compatible endpoints.",
208
123
  "清空": "Clear",
209
124
  "清空当前请求头,重新手动填写。": "Clear the current headers and enter them manually.",
210
- "未抓包": "Not captured",
211
- "已抓包 {time} · {count} headers": "Captured {time} · {count} headers",
212
- "自定义 ID": "Custom ID",
213
- "请求头 ID": "Header ID",
214
- "请求头名称": "Header name",
125
+ "字段": "Fields",
126
+ "使用接入": "Used by",
127
+ "请求头名称重复(不区分大小写):{name}": "Duplicate header name (case-insensitive): {name}",
128
+ "请求头名称无效:{name}": "Invalid header name: {name}",
129
+ "请求头值包含 HTTP 不支持的字符:{name}": "Header value contains characters unsupported by HTTP: {name}",
130
+ "{label} 名称重复:{key}": "Duplicate {label} name: {key}",
131
+ "配置已保存,但后续同步失败:{error}。可执行 /reload 重试。": "Configuration saved, but subsequent synchronization failed: {error}. Run /reload to retry.",
215
132
  "快速模板": "Quick template",
216
- "选择后填充": "Select to populate",
217
- "请求头 JSON": "Header JSON",
218
- "{count}项": "{count} entries",
219
- "未配置": "Not configured",
220
- "请求头无效:\n{errors}": "Invalid headers:\n{errors}",
221
- "结构:JSON 对象;key 是客户端 header 名,value 是字符串。复杂示例请用“快速模板”。": "Format: a JSON object whose keys are client header names and values are strings. Use Quick template for complete examples.",
222
- "请求头 JSON 无效:{error}": "Invalid header JSON: {error}",
223
- "选择请求头模板": "Select a header template",
224
- "已清空请求头": "Headers cleared",
225
- "已填充模板:{template},可继续进入“请求头 JSON”微调。": "Template applied: {template}. Open Header JSON to customize it.",
226
- "请求头 ID(接入引用这个 ID;字母/数字/._-)": "Header ID (referenced by providers; letters/digits/._-)",
227
- "请求头名称(显示用)": "Header name (display only)",
228
- "认证类敏感 header 会被拒绝;API key 请放在接入配置中": "Sensitive authentication headers are rejected; configure the API key on the provider instead",
229
133
  "请求头不存在:{profileId}": "Header profile not found: {profileId}",
230
134
  "删除请求头 {profileId}": "Delete header profile {profileId}",
231
- "将删除 {name}。{affected}": "Delete {name}.{affected}",
232
- "\n{count} 个模型会自动改回“自动推荐”。": "\nAffected models ({count}) will automatically revert to Recommended.",
233
- "编辑请求头 {profileId}": "Edit header profile {profileId}",
234
- "/model-manager / 请求头": "/model-manager / Headers",
235
- "编辑请求头": "Edit headers",
236
135
  "新建自定义": "New custom profile",
237
136
  "删除": "Delete",
238
- "暂无自定义请求头;按 n 新建": "No custom header profiles. Press N to create one.",
239
- "新建请求头": "New header profile",
240
- "没有可删除的请求头。": "There are no header profiles to delete.",
241
137
 
242
138
  "模型接入与请求配置 / Model and provider settings": "Model and provider settings / 模型接入与请求配置",
243
139
  "/model-manager 需要 TUI 交互模式": "/model-manager requires interactive TUI mode",
244
140
 
245
- "可先返回上一级选择“快速模板”,也可在这里填写:": "Return to Quick template first, or enter headers here:",
246
-
247
141
  "恢复未完成配置事务失败:{error}(为避免读取半完成配置,本次暂不注册模型)": "Failed to recover an incomplete configuration transaction: {error} (models will not be registered this time to avoid reading a partially written configuration)",
248
142
  "读取 models.json/state.json 失败:{error}(本次启动仅使用内存空配置,不覆盖原文件)": "Failed to read models.json/state.json: {error} (this startup will use an empty in-memory configuration without overwriting the files)",
249
143
  "注册模型目录失败:{warning}": "Failed to register the model catalog: {warning}",
@@ -251,7 +145,7 @@ const ENGLISH_MESSAGES = {
251
145
  "激活模型接入失败:{warning}": "Failed to activate a model provider: {warning}",
252
146
  "恢复、读取或激活模型配置失败:{error}": "Failed to recover, read, or activate the model configuration: {error}",
253
147
  "[pi-model-manager] 已规范化 {count} 个接入的 API 根地址({providerIds})": "[pi-model-manager] Normalized API root URLs for {count} provider(s) ({providerIds})",
254
- "[pi-model-manager] 已升级端点配置;迁移前快照保存在插件配置目录的 base-url-v5-*.json": "[pi-model-manager] Endpoint configuration upgraded; pre-migration snapshots are saved as base-url-v5-*.json in the plugin configuration directory",
148
+ "[pi-model-manager] 已升级配置;迁移前快照保存在插件配置目录的 configuration-v6-*.json": "[pi-model-manager] Configuration upgraded; pre-migration snapshots are saved as configuration-v6-*.json in the plugin configuration directory",
255
149
  "迁移备份内容不匹配:{path}": "Migration backup content does not match: {path}",
256
150
 
257
151
  "{label} JSON 必须是对象": "{label} JSON must be an object",
@@ -277,9 +171,7 @@ const ENGLISH_MESSAGES = {
277
171
  "models.json/state.json 已写入,但当前会话 registry 重载失败:{error}。可执行 /reload 重试。": "models.json/state.json were written, but the current session registry failed to reload: {error}. Run /reload to retry.",
278
172
  "{path} 在读取期间持续变化;请停止其它写入后重试。": "{path} kept changing while being read; stop other writers and try again.",
279
173
 
280
- "{successMessage},但以下接入未能刷新,已保留上一版 runtime:\n- {warnings}": "{successMessage}, but the following providers could not be refreshed and retain their previous runtime:\n- {warnings}",
281
174
  "已保存请求头 {profileId}": "Saved header profile {profileId}",
282
- "请求头 {profileId} 尚未被任何接入使用;在接入编辑器的「请求头」行选择后才会生效。": "Header profile {profileId} is not used by any provider yet; select it in the provider editor's request-header row to take effect.",
283
175
  "已删除请求头 {profileId}": "Deleted header profile {profileId}",
284
176
  "代理地址无效:{url}": "Invalid proxy URL: {url}",
285
177
  "代理地址目前只支持 http:// 或 https:// 代理": "Only http:// or https:// proxies are currently supported",
@@ -299,11 +191,10 @@ const ENGLISH_MESSAGES = {
299
191
  "已写入全局 enabledModels": "Written to global enabledModels",
300
192
  "已在 enabledModels 中": "Already present in enabledModels",
301
193
  "已保存并启用模型": "Saved and enabled model",
302
- "已创建并启用模型": "Created and enabled model",
194
+ "已保存模型 {fullId}": "Saved model {fullId}",
303
195
  "{messagePrefix} {fullId}({availability})": "{messagePrefix} {fullId} ({availability})",
304
196
  "已保存模型 {fullId},但启用校验有警告:\n- {warnings}": "Saved model {fullId}, but availability verification reported warnings:\n- {warnings}",
305
197
  "已保存模型 {fullId},但启用同步/校验失败:{error}": "Saved model {fullId}, but availability synchronization/verification failed: {error}",
306
- "models.json/state.json 已保存,但当前会话接入刷新失败:{error}。可执行 /reload 重试。": "models.json/state.json were saved, but the current session provider refresh failed: {error}. Run /reload to retry.",
307
198
  "已保存接入 {providerId}": "Saved provider {providerId}",
308
199
  "已同步项目 enabledModels 中的接入重命名": "Synchronized the provider rename in project enabledModels",
309
200
  "已同步全局 enabledModels 中的接入重命名": "Synchronized the provider rename in global enabledModels",
@@ -351,7 +242,6 @@ const ENGLISH_MESSAGES = {
351
242
  "{reason},已自动切换到 {fullId}": "{reason}; automatically switched to {fullId}",
352
243
  "{reason},但当前没有其它可用模型。请使用 /model-manager 添加模型或 /login 配置认证。": "{reason}, but no other model is currently available. Use /model-manager to add a model or /login to configure authentication.",
353
244
 
354
- "{label} 必须使用 http 或 https": "{label} must use http or https",
355
245
  "{label} 不是有效 URL": "{label} is not a valid URL",
356
246
  "代理地址必须包含主机名": "The proxy URL must include a hostname",
357
247
  "代理地址不是有效 URL": "The proxy URL is invalid",
@@ -386,16 +276,8 @@ const ENGLISH_MESSAGES = {
386
276
  "值必须是字符串": "value must be a string",
387
277
  "必须是字符串数组": "must be an array of strings",
388
278
  "必须是字符串或 null": "must be a string or null",
389
- "必须是有限数字": "must be a finite number",
390
- "必须是非负数": "must be non-negative",
391
279
  "必须是数组": "must be an array",
392
280
  "必须是 text 或 image": "must be text or image",
393
- "必须是合法 API 协议": "must be a valid API protocol",
394
- "必须是合法请求头配置": "must be a valid header profile",
395
- "必须是合法 service tier": "must be a valid service tier",
396
- "状态文件格式无效:{details}": "Invalid state file format: {details}",
397
- "状态文件版本不受支持:{version}": "Unsupported state file version: {version}",
398
- "读取状态文件失败:{error}": "Failed to read the state file: {error}",
399
281
  "state.json {path}: {message}": "state.json {path}: {message}",
400
282
  "未知 API 协议:{value}": "unknown API protocol: {value}",
401
283
  "未知请求头:{value}": "unknown request-header profile: {value}",
@@ -404,7 +286,6 @@ const ENGLISH_MESSAGES = {
404
286
  "必须是非负数字": "must be a non-negative number",
405
287
  "未知 thinking level": "unknown thinking level",
406
288
  "不能使用插件内置请求头保留名": "cannot use a request-header name reserved by the plugin",
407
- "只能保存 ClaudeCode/Codex 内置 profile 的抓包数据": "only captured data for the built-in ClaudeCode/Codex profiles can be saved",
408
289
  "根节点必须是对象": "root must be an object",
409
290
  "不支持的版本:{version}": "unsupported version: {version}",
410
291
  "models.json/state.json 正在事务更新或持续变化;请稍后重试。": "models.json/state.json is being updated by a transaction or changing continuously. Please try again shortly.",