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/README.en.md
CHANGED
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
English · [简体中文](./README.md)
|
|
4
4
|
|
|
5
|
-
[](https://github.com/earendil-works/pi)
|
|
6
6
|
[](./LICENSE)
|
|
7
|
-
[](https://github.com/Qihuanxishini/pi-model-manager)
|
|
8
8
|
|
|
9
9
|
A TUI model and provider manager for [Pi](https://github.com/earendil-works/pi). It keeps Pi's native `models.json` as the single source of truth for model configuration while adding provider/model editing, client-header identities, proxy routing, and protocol compatibility controls.
|
|
10
10
|
|
|
11
|
-
> The current stable version is `0.3.
|
|
11
|
+
> The current stable version is `0.3.1` and requires Pi `>=0.84.2`.
|
|
12
12
|
|
|
13
13
|
## Interface preview
|
|
14
14
|
|
|
15
|
-
The screens below are rendered by the real components at 88 columns. In practice column widths adapt to your data, the selected row is highlighted with a background colour, and column values are semantically coloured.
|
|
15
|
+
The screens below are rendered by the real components at 88 columns. In practice column widths adapt to your data, the selected row is highlighted with a background colour, and column values are semantically coloured. This preview uses Simplified Chinese; the live UI can switch between Simplified Chinese and English from the dashboard.
|
|
16
16
|
|
|
17
17
|
```text
|
|
18
18
|
────────────────────────────────────────────────────────────────────────────────────────
|
|
@@ -126,6 +126,7 @@ Ctrl+S 保存并启用模型;不切换当前会话模型
|
|
|
126
126
|
## Features
|
|
127
127
|
|
|
128
128
|
- Create, edit, and delete providers and models from the `/model-manager` TUI.
|
|
129
|
+
- Start in Simplified Chinese and press `L` on the dashboard to switch to English; the language preference is saved.
|
|
129
130
|
- Supports `openai-completions`, `openai-responses`, `anthropic-messages`, and `google-generative-ai`.
|
|
130
131
|
- Fetch model IDs from compatible upstream APIs or enter them manually.
|
|
131
132
|
- Configure context window, maximum output, vision support, and reasoning support.
|
|
@@ -181,6 +182,7 @@ pi install npm:pi-model-manager
|
|
|
181
182
|
| `N` | Create a provider and its first model |
|
|
182
183
|
| `D` | Delete the selected provider |
|
|
183
184
|
| `H` | Manage reusable header profiles |
|
|
185
|
+
| `L` | Switch the UI language (Simplified Chinese / English); the choice applies immediately and is saved |
|
|
184
186
|
| `/` | Search the current list; `Tab` leaves the input while keeping the filter, `Esc` clears it |
|
|
185
187
|
| `Esc` | Go back or exit |
|
|
186
188
|
|
|
@@ -266,11 +268,11 @@ Additional considerations:
|
|
|
266
268
|
|
|
267
269
|
| Component | Requirement |
|
|
268
270
|
| --- | --- |
|
|
269
|
-
| `@earendil-works/pi-coding-agent` | `>=0.
|
|
271
|
+
| `@earendil-works/pi-coding-agent` | `>=0.84.2` |
|
|
270
272
|
| `@earendil-works/pi-tui` | `>=0.75.0` |
|
|
271
273
|
| Runtime mode | `/model-manager` requires the Pi TUI |
|
|
272
274
|
|
|
273
|
-
The
|
|
275
|
+
The TUI copy defaults to Simplified Chinese; press `L` on the dashboard to switch to English.
|
|
274
276
|
|
|
275
277
|
## Local development
|
|
276
278
|
|
package/README.md
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
[English](./README.en.md) · 简体中文
|
|
4
4
|
|
|
5
|
-
[](https://github.com/earendil-works/pi)
|
|
6
6
|
[](./LICENSE)
|
|
7
|
-
[](https://github.com/Qihuanxishini/pi-model-manager)
|
|
8
8
|
|
|
9
9
|
一个面向 [Pi](https://github.com/earendil-works/pi) 的 TUI 模型与接入管理扩展。它以 Pi 原生 `models.json` 为模型配置的唯一权威来源,并提供接入/模型编辑、请求头身份、代理路由和协议兼容配置。
|
|
10
10
|
|
|
11
|
-
> 当前稳定版为 `0.3.
|
|
11
|
+
> 当前稳定版为 `0.3.1`,要求 Pi `>=0.84.2`。
|
|
12
12
|
|
|
13
13
|
## 界面预览
|
|
14
14
|
|
|
@@ -126,6 +126,7 @@ Ctrl+S 保存并启用模型;不切换当前会话模型
|
|
|
126
126
|
## 功能
|
|
127
127
|
|
|
128
128
|
- 在 `/model-manager` TUI 中新增、编辑和删除接入与模型。
|
|
129
|
+
- 界面默认使用简体中文;可在主面板按 `L` 切换为 English,语言选择会持久保存。
|
|
129
130
|
- 原生支持 `openai-completions`、`openai-responses`、`anthropic-messages` 和 `google-generative-ai`。
|
|
130
131
|
- 从兼容上游拉取模型 ID,也可手动填写模型。
|
|
131
132
|
- 配置上下文窗口、最大输出、视觉支持和 Thinking。
|
|
@@ -181,6 +182,7 @@ pi install npm:pi-model-manager
|
|
|
181
182
|
| `N` | 新建接入及其第一个模型 |
|
|
182
183
|
| `D` | 删除所选接入 |
|
|
183
184
|
| `H` | 管理可复用请求头 |
|
|
185
|
+
| `L` | 切换界面语言(简体中文 / English),选择后立即生效并持久保存 |
|
|
184
186
|
| `/` | 搜索当前列表;`Tab` 退出输入但保留过滤,`Esc` 清空 |
|
|
185
187
|
| `Esc` | 返回或退出 |
|
|
186
188
|
|
|
@@ -270,11 +272,11 @@ ${ANTHROPIC_API_KEY}
|
|
|
270
272
|
|
|
271
273
|
| 组件 | 要求 |
|
|
272
274
|
| --- | --- |
|
|
273
|
-
| `@earendil-works/pi-coding-agent` | `>=0.
|
|
275
|
+
| `@earendil-works/pi-coding-agent` | `>=0.84.2` |
|
|
274
276
|
| `@earendil-works/pi-tui` | `>=0.75.0` |
|
|
275
277
|
| 运行模式 | `/model-manager` 需要 Pi TUI |
|
|
276
278
|
|
|
277
|
-
|
|
279
|
+
默认 TUI 文案为简体中文;可在主面板按 `L` 切换为 English。
|
|
278
280
|
|
|
279
281
|
## 本地开发
|
|
280
282
|
|
package/atomic-write.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import { randomUUID } from "node:crypto";
|
|
8
8
|
import { mkdir, rename, unlink, writeFile } from "node:fs/promises";
|
|
9
9
|
import { dirname } from "node:path";
|
|
10
|
+
import { t } from "./i18n.ts";
|
|
10
11
|
|
|
11
12
|
const REPLACE_RETRY_DELAYS_MS = [25, 50, 100, 200, 400, 800] as const;
|
|
12
13
|
const TRANSIENT_REPLACE_ERROR_CODES = new Set(["EACCES", "EPERM", "EBUSY", "ENOTEMPTY"]);
|
|
@@ -66,7 +67,8 @@ export async function atomicWriteText(targetPath: string, content: string): Prom
|
|
|
66
67
|
await renameWithRetry(tempPath, targetPath);
|
|
67
68
|
} catch (error) {
|
|
68
69
|
if (!tempHasCompleteContent) await removeTempFile(tempPath);
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
throw new Error(tempHasCompleteContent
|
|
71
|
+
? t("写入 {targetPath} 失败;完整内容已保留在临时文件:{tempPath}:{error}", { targetPath, tempPath, error: formatError(error) })
|
|
72
|
+
: t("写入 {targetPath} 失败:{error}", { targetPath, error: formatError(error) }));
|
|
71
73
|
}
|
|
72
74
|
}
|
package/common.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// 通用小工具:JSON 解析、字符串处理、错误格式化、克隆。
|
|
2
2
|
// 与 pi-model-add/common.ts 等价;后续 step 不再依赖旧插件。
|
|
3
3
|
|
|
4
|
+
import { t } from "./i18n.ts";
|
|
4
5
|
export function isObjectRecord(value: unknown): value is Record<string, unknown> {
|
|
5
6
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
6
7
|
}
|
|
@@ -30,10 +31,10 @@ export function hasStringRecordEntries(record: Record<string, string> | undefine
|
|
|
30
31
|
|
|
31
32
|
export function parseStringRecordJson(source: string, label: string): Record<string, string> {
|
|
32
33
|
const parsed = JSON.parse(stripJsonNoise(source));
|
|
33
|
-
if (!isObjectRecord(parsed)) throw new Error(
|
|
34
|
+
if (!isObjectRecord(parsed)) throw new Error(t("{label} JSON 必须是对象", { label }));
|
|
34
35
|
const record: Record<string, string> = {};
|
|
35
36
|
for (const [key, value] of Object.entries(parsed)) {
|
|
36
|
-
if (typeof value !== "string") throw new Error(
|
|
37
|
+
if (typeof value !== "string") throw new Error(t("{label} {key} 的值必须是字符串", { label, key }));
|
|
37
38
|
const trimmedKey = key.trim();
|
|
38
39
|
if (trimmedKey) record[trimmedKey] = value;
|
|
39
40
|
}
|
package/configuration-lock.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { hostname } from "node:os";
|
|
|
4
4
|
import { open, mkdir, readFile, stat, unlink, type FileHandle } from "node:fs/promises";
|
|
5
5
|
import { join } from "node:path";
|
|
6
6
|
import { randomUUID } from "node:crypto";
|
|
7
|
+
import { t } from "./i18n.ts";
|
|
7
8
|
import { STATE_DIR } from "./state-metadata-store.ts";
|
|
8
9
|
|
|
9
10
|
interface ConfigurationLockRecord {
|
|
@@ -108,7 +109,7 @@ async function acquireConfigurationLock(): Promise<HeldConfigurationLock> {
|
|
|
108
109
|
await sleep(LOCK_RETRY_DELAYS_MS[attempt]!);
|
|
109
110
|
}
|
|
110
111
|
}
|
|
111
|
-
throw new Error(
|
|
112
|
+
throw new Error(t("另一个 Pi 进程正在保存模型配置;无法在限定时间内获取锁:{path}", { path: LOCK_PATH }));
|
|
112
113
|
}
|
|
113
114
|
|
|
114
115
|
async function releaseConfigurationLock(lock: HeldConfigurationLock): Promise<void> {
|
|
@@ -121,7 +122,7 @@ async function releaseConfigurationLock(lock: HeldConfigurationLock): Promise<vo
|
|
|
121
122
|
throw error;
|
|
122
123
|
}
|
|
123
124
|
if (current?.token !== lock.record.token) {
|
|
124
|
-
throw new Error(
|
|
125
|
+
throw new Error(t("配置锁所有权在释放前发生变化,已保留锁文件供检查:{path}", { path: LOCK_PATH }));
|
|
125
126
|
}
|
|
126
127
|
await unlink(LOCK_PATH);
|
|
127
128
|
}
|
|
@@ -11,6 +11,7 @@ import { atomicWriteText } from "./atomic-write.ts";
|
|
|
11
11
|
import { formatUnknownError, isObjectRecord, stringifyJson } from "./common.ts";
|
|
12
12
|
import { withConfigurationLock } from "./configuration-lock.ts";
|
|
13
13
|
import { hashTextContent, readStableTextFileSnapshot } from "./file-snapshot.ts";
|
|
14
|
+
import { t } from "./i18n.ts";
|
|
14
15
|
import {
|
|
15
16
|
MODELS_JSON_PATH,
|
|
16
17
|
markManagedProvidersInDoc,
|
|
@@ -74,18 +75,18 @@ function createTransition(oldSource: string | undefined, targetSource: string):
|
|
|
74
75
|
}
|
|
75
76
|
|
|
76
77
|
function readTransition(raw: unknown, path: string): FileTransition {
|
|
77
|
-
if (!isObjectRecord(raw)) throw new Error(
|
|
78
|
+
if (!isObjectRecord(raw)) throw new Error(t("{path} 必须是对象", { path }));
|
|
78
79
|
const oldSource = raw.oldSource;
|
|
79
80
|
const oldHash = raw.oldHash;
|
|
80
81
|
const targetSource = raw.targetSource;
|
|
81
82
|
const targetHash = raw.targetHash;
|
|
82
|
-
if (oldSource !== null && typeof oldSource !== "string") throw new Error(
|
|
83
|
+
if (oldSource !== null && typeof oldSource !== "string") throw new Error(t("{path}.oldSource 必须是字符串或 null", { path }));
|
|
83
84
|
if (typeof oldHash !== "string" || typeof targetSource !== "string" || typeof targetHash !== "string") {
|
|
84
|
-
throw new Error(
|
|
85
|
+
throw new Error(t("{path} 缺少有效内容或签名", { path }));
|
|
85
86
|
}
|
|
86
87
|
const normalizedOldSource = oldSource === null ? undefined : oldSource;
|
|
87
88
|
if (hashTextContent(normalizedOldSource) !== oldHash || hashTextContent(targetSource) !== targetHash) {
|
|
88
|
-
throw new Error(
|
|
89
|
+
throw new Error(t("{path} 内容签名校验失败", { path }));
|
|
89
90
|
}
|
|
90
91
|
return { oldSource, oldHash, targetSource, targetHash };
|
|
91
92
|
}
|
|
@@ -93,7 +94,7 @@ function readTransition(raw: unknown, path: string): FileTransition {
|
|
|
93
94
|
function parseTransactionJournal(source: string): ConfigurationTransactionJournal {
|
|
94
95
|
const raw = JSON.parse(source);
|
|
95
96
|
if (!isObjectRecord(raw) || raw.version !== 1 || typeof raw.createdAt !== "string") {
|
|
96
|
-
throw new Error("事务意图文件格式无效");
|
|
97
|
+
throw new Error(t("事务意图文件格式无效"));
|
|
97
98
|
}
|
|
98
99
|
return {
|
|
99
100
|
version: 1,
|
|
@@ -115,14 +116,14 @@ async function classifyTransition(path: string, transition: FileTransition): Pro
|
|
|
115
116
|
const current = await readStableTextFileSnapshot(path);
|
|
116
117
|
if (current.contentHash === transition.targetHash) return "target";
|
|
117
118
|
if (current.contentHash === transition.oldHash) return "old";
|
|
118
|
-
throw new Error(
|
|
119
|
+
throw new Error(t("{path} 的当前内容既不是事务旧版本,也不是目标版本;已保留 {transactionPath},不会覆盖外部修改。", { path, transactionPath: TRANSACTION_PATH }));
|
|
119
120
|
}
|
|
120
121
|
|
|
121
122
|
async function finishTransition(path: string, transition: FileTransition, status: "old" | "target"): Promise<void> {
|
|
122
123
|
if (status === "old") await atomicWriteText(path, transition.targetSource);
|
|
123
124
|
const completed = await readStableTextFileSnapshot(path);
|
|
124
125
|
if (completed.contentHash !== transition.targetHash) {
|
|
125
|
-
throw new Error(
|
|
126
|
+
throw new Error(t("{path} 写入后内容签名不匹配;已保留 {transactionPath} 供恢复。", { path, transactionPath: TRANSACTION_PATH }));
|
|
126
127
|
}
|
|
127
128
|
}
|
|
128
129
|
|
|
@@ -133,7 +134,7 @@ async function recoverPendingConfigurationTransactionInsideLock(): Promise<boole
|
|
|
133
134
|
try {
|
|
134
135
|
journal = parseTransactionJournal(journalSnapshot.source);
|
|
135
136
|
} catch (error) {
|
|
136
|
-
throw new Error(
|
|
137
|
+
throw new Error(t("无法解析未完成事务 {transactionPath}:{error}", { transactionPath: TRANSACTION_PATH, error: formatUnknownError(error) }));
|
|
137
138
|
}
|
|
138
139
|
|
|
139
140
|
// 先同时判定两端,任何一端存在外部修改时都不继续写另一端。
|
|
@@ -155,7 +156,7 @@ export async function recoverPendingConfigurationTransaction(): Promise<boolean>
|
|
|
155
156
|
async function assertSnapshotStillCurrent(path: string, expectedHash: string): Promise<void> {
|
|
156
157
|
const current = await readStableTextFileSnapshot(path);
|
|
157
158
|
if (current.contentHash !== expectedHash) {
|
|
158
|
-
throw new Error(
|
|
159
|
+
throw new Error(t("{path} 已被其它进程或编辑器修改;已取消本次保存,请重新打开 /model-manager 后重试。", { path }));
|
|
159
160
|
}
|
|
160
161
|
}
|
|
161
162
|
|
|
@@ -186,7 +187,7 @@ async function writeConfigurationTransaction(
|
|
|
186
187
|
await finishTransition(STATE_PATH, journal.metadataState, metadataStatus);
|
|
187
188
|
await removeTransactionJournal();
|
|
188
189
|
} catch (error) {
|
|
189
|
-
throw new Error(
|
|
190
|
+
throw new Error(t("配置事务未完成:{error}。下次启动或保存会尝试恢复。", { error: formatUnknownError(error) }));
|
|
190
191
|
}
|
|
191
192
|
}
|
|
192
193
|
|
|
@@ -232,12 +233,12 @@ async function refreshRegistryAfterPersistence(
|
|
|
232
233
|
document = await withConfigurationLock(persist);
|
|
233
234
|
invalidateStateCache();
|
|
234
235
|
} catch (error) {
|
|
235
|
-
throw new Error(
|
|
236
|
+
throw new Error(t("models.json/state.json 未完整保存:{error}", { error: formatUnknownError(error) }));
|
|
236
237
|
}
|
|
237
238
|
try {
|
|
238
239
|
await ctx.modelRegistry.refresh();
|
|
239
240
|
} catch (error) {
|
|
240
|
-
throw new Error(
|
|
241
|
+
throw new Error(t("models.json/state.json 已写入,但当前会话 registry 重载失败:{error}。可执行 /reload 重试。", { error: formatUnknownError(error) }));
|
|
241
242
|
}
|
|
242
243
|
return document;
|
|
243
244
|
}
|
package/file-snapshot.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { createHash } from "node:crypto";
|
|
4
4
|
import { readFile, stat } from "node:fs/promises";
|
|
5
|
+
import { t } from "./i18n.ts";
|
|
5
6
|
|
|
6
7
|
export interface FileSignature {
|
|
7
8
|
exists: boolean;
|
|
@@ -72,5 +73,5 @@ export async function readStableTextFileSnapshot(path: string): Promise<StableTe
|
|
|
72
73
|
return { source, signature: after, contentHash: hashTextContent(source) };
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
|
-
throw new Error(
|
|
76
|
+
throw new Error(t("{path} 在读取期间持续变化;请停止其它写入后重试。", { path }));
|
|
76
77
|
}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
6
6
|
import { persistManagedConfiguration } from "./configuration-persistence.ts";
|
|
7
|
+
import { t } from "./i18n.ts";
|
|
7
8
|
import { registerAllFromState } from "./provider-registrar.ts";
|
|
8
9
|
import { deleteRequestHeaderProfileFromDocument, upsertRequestHeaderProfileInDocument } from "./state-document.ts";
|
|
9
10
|
import type { RequestHeaderProfileDraft, StateDocument, StoredProvider } from "./types.ts";
|
|
@@ -32,7 +33,7 @@ function notifyHeaderProfileRefresh(
|
|
|
32
33
|
ctx.ui.notify(successMessage, "info");
|
|
33
34
|
return;
|
|
34
35
|
}
|
|
35
|
-
ctx.ui.notify(
|
|
36
|
+
ctx.ui.notify(t("{successMessage},但以下接入未能刷新,已保留上一版 runtime:\n- {warnings}", { successMessage, warnings: warnings.join("\n- ") }), "warning");
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
export async function saveRequestHeaderProfileConfiguration(
|
|
@@ -49,7 +50,7 @@ export async function saveRequestHeaderProfileConfiguration(
|
|
|
49
50
|
removedProviderIds: [],
|
|
50
51
|
}));
|
|
51
52
|
const warnings = await registerAllFromState(pi, nextState);
|
|
52
|
-
notifyHeaderProfileRefresh(ctx,
|
|
53
|
+
notifyHeaderProfileRefresh(ctx, t("已保存请求头 {profileId}", { profileId: draft.profileId.trim() }), warnings);
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
export async function deleteRequestHeaderProfileConfiguration(
|
|
@@ -64,5 +65,5 @@ export async function deleteRequestHeaderProfileConfiguration(
|
|
|
64
65
|
removedProviderIds: [],
|
|
65
66
|
}));
|
|
66
67
|
const warnings = await registerAllFromState(pi, nextState);
|
|
67
|
-
notifyHeaderProfileRefresh(ctx,
|
|
68
|
+
notifyHeaderProfileRefresh(ctx, t("已删除请求头 {profileId}", { profileId }), warnings);
|
|
68
69
|
}
|