pi-model-manager 0.2.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 +118 -23
- package/README.md +118 -23
- package/atomic-write.ts +4 -2
- package/common.ts +3 -2
- package/configuration-lock.ts +3 -2
- package/configuration-persistence.ts +24 -19
- package/file-snapshot.ts +2 -1
- package/header-profile-mutations.ts +4 -3
- package/i18n.ts +403 -0
- package/index.ts +39 -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 +5 -4
- package/presets/builtin-client-headers.ts +7 -7
- package/presets/client-headers.ts +9 -9
- package/presets/providers.ts +6 -3
- package/provider-registrar.ts +4 -3
- package/request-pipeline.ts +3 -2
- package/rescue.ts +4 -3
- package/runtime-base-url.ts +9 -3
- package/state-document.ts +58 -34
- package/state-metadata-store.ts +38 -37
- package/state-store.ts +2 -1
- package/tui/dashboard.ts +110 -53
- package/tui/editor-model.ts +78 -116
- package/tui/editor-provider.ts +77 -76
- package/tui/header-profiles-panel.ts +100 -76
- package/tui/model-list-fetch.ts +9 -8
- package/tui/model-list-validation.ts +8 -7
- package/tui/model-picker.ts +18 -11
- package/tui/persistent-menu.ts +231 -87
- package/tui/ui-helpers.ts +184 -121
- package/ui-language-settings.ts +47 -0
package/README.en.md
CHANGED
|
@@ -2,44 +2,134 @@
|
|
|
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.
|
|
11
|
+
> The current stable version is `0.3.1` and requires Pi `>=0.84.2`.
|
|
12
12
|
|
|
13
13
|
## Interface preview
|
|
14
14
|
|
|
15
|
-
|
|
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
|
+
|
|
17
|
+
```text
|
|
18
|
+
────────────────────────────────────────────────────────────────────────────────────────
|
|
19
|
+
/model-manager
|
|
20
|
+
4 接入 · 5 模型 · 0 内置抓包 · 0 自定义请求头
|
|
21
|
+
|
|
22
|
+
接入 API 模型 请求头 代理 认证 状态
|
|
23
|
+
❯ OpenAI (openai) Responses 2 Auto→Codex direct env ready
|
|
24
|
+
Claude (claude) Claude 1 ClaudeCode direct env ready
|
|
25
|
+
Gemini (gemini) Gemini 1 Auto→不添加 direct env ready
|
|
26
|
+
Local vLLM (local) Chat 1 Off proxy key ready
|
|
27
|
+
|
|
28
|
+
────────────────────────────────────────────────────────────────────────────────────────
|
|
29
|
+
OpenAI (openai)
|
|
30
|
+
endpoint https://api.openai.com/v1
|
|
31
|
+
proxy direct
|
|
32
|
+
api Responses · headers Auto→Codex · auth env
|
|
33
|
+
models gpt-5.1, gpt-5.1-mini
|
|
34
|
+
|
|
35
|
+
↑↓ 选择 Enter 进入 N 新建接入 D 删除接入 H 请求头 Esc 退出 / 搜索
|
|
36
|
+
────────────────────────────────────────────────────────────────────────────────────────
|
|
37
|
+
```
|
|
16
38
|
|
|
17
39
|
<details>
|
|
18
|
-
<summary>
|
|
40
|
+
<summary>Show the other four screens</summary>
|
|
19
41
|
|
|
20
|
-
###
|
|
42
|
+
### Models inside a provider
|
|
21
43
|
|
|
22
|
-
|
|
44
|
+
```text
|
|
45
|
+
────────────────────────────────────────────────────────────────────────────────────────
|
|
46
|
+
/model-manager / OpenAI
|
|
47
|
+
Responses · 2 模型 · headers Auto→Codex · proxy direct · auth env
|
|
48
|
+
endpoint https://api.openai.com/v1
|
|
23
49
|
|
|
24
|
-
|
|
50
|
+
模型 ID 显示名 输入 Thinking 上下文
|
|
51
|
+
❯ gpt-5.1 默认 文本,视觉 开 400K
|
|
52
|
+
gpt-5.1-mini 默认 文本,视觉 开 400K
|
|
25
53
|
|
|
26
|
-
|
|
54
|
+
↑↓ 选择 Enter 编辑模型 A 添加模型 E 编辑接入 D 删除模型 Esc 返回 / 搜索
|
|
55
|
+
────────────────────────────────────────────────────────────────────────────────────────
|
|
56
|
+
```
|
|
27
57
|
|
|
28
|
-
### Provider
|
|
58
|
+
### Provider setup
|
|
29
59
|
|
|
30
|
-
|
|
60
|
+
```text
|
|
61
|
+
────────────────────────────────────────────────────────────────────────────────────────
|
|
62
|
+
编辑接入 openai
|
|
63
|
+
API Responses · 请求头 自动推荐(Auto→Codex)
|
|
64
|
+
接入 ID 必填,且不能与已有或 pi 内置接入重复
|
|
65
|
+
Ctrl+S 保存并同步 models.json;不切换当前会话模型
|
|
66
|
+
|
|
67
|
+
接入 ID openai
|
|
68
|
+
显示名称 OpenAI
|
|
69
|
+
API 协议 OpenAI Responses
|
|
70
|
+
❯ Base URL https://api.openai.com/v1
|
|
71
|
+
本机代理 关闭
|
|
72
|
+
代理地址 关闭时不使用
|
|
73
|
+
API key $OPENAI_API_KEY
|
|
74
|
+
认证头 默认
|
|
75
|
+
请求头 自动推荐(Auto→Codex)
|
|
76
|
+
|
|
77
|
+
↑↓ 选择 ←→ 切换选项 Enter 编辑 Ctrl+S 保存并同步 Esc 返回
|
|
78
|
+
────────────────────────────────────────────────────────────────────────────────────────
|
|
79
|
+
```
|
|
31
80
|
|
|
32
81
|
### Model capabilities
|
|
33
82
|
|
|
34
|
-
|
|
83
|
+
```text
|
|
84
|
+
────────────────────────────────────────────────────────────────────────────────────────
|
|
85
|
+
编辑模型 gpt-5.1
|
|
86
|
+
接入 openai · API Responses
|
|
87
|
+
Ctrl+S 保存并启用模型;不切换当前会话模型
|
|
88
|
+
|
|
89
|
+
模型 ID gpt-5.1
|
|
90
|
+
重新拉取 上游模型列表
|
|
91
|
+
显示名称 默认 = 模型 ID
|
|
92
|
+
❯ 视觉支持 开启
|
|
93
|
+
Thinking 开启
|
|
94
|
+
Fast mode 关闭
|
|
95
|
+
上下文窗口 400000
|
|
96
|
+
最大输出 128000
|
|
97
|
+
请求头 跟随接入(Auto→Codex)
|
|
98
|
+
|
|
99
|
+
↑↓ 选择 ←→ 切换选项 Enter 编辑 Ctrl+S 保存并启用 Esc 返回
|
|
100
|
+
────────────────────────────────────────────────────────────────────────────────────────
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Model discovery
|
|
104
|
+
|
|
105
|
+
```text
|
|
106
|
+
────────────────────────────────────────────────────────────────────────────────────────
|
|
107
|
+
选择模型(openai)
|
|
108
|
+
搜索: <直接输入搜索>
|
|
109
|
+
匹配 9 / 9 · 页码 1 / 2
|
|
110
|
+
|
|
111
|
+
dall-e-3
|
|
112
|
+
gpt-4.1
|
|
113
|
+
gpt-4.1-mini
|
|
114
|
+
❯ gpt-5.1 ← 当前
|
|
115
|
+
gpt-5.1-codex
|
|
116
|
+
gpt-5.1-mini
|
|
117
|
+
o4-mini
|
|
118
|
+
text-embedding-3-large
|
|
119
|
+
|
|
120
|
+
↑↓ 选择 · ←→/PgUp/PgDn 翻页 · 输入搜索 · Backspace 删除 · Enter 确认 · Esc 取消
|
|
121
|
+
────────────────────────────────────────────────────────────────────────────────────────
|
|
122
|
+
```
|
|
35
123
|
|
|
36
124
|
</details>
|
|
125
|
+
|
|
37
126
|
## Features
|
|
38
127
|
|
|
39
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.
|
|
40
130
|
- Supports `openai-completions`, `openai-responses`, `anthropic-messages`, and `google-generative-ai`.
|
|
41
131
|
- Fetch model IDs from compatible upstream APIs or enter them manually.
|
|
42
|
-
- Configure context window, maximum output, vision
|
|
132
|
+
- Configure context window, maximum output, vision support, and reasoning support.
|
|
43
133
|
- Choose Anthropic Adaptive Thinking or Legacy Thinking.
|
|
44
134
|
- Enable `service_tier=priority` (Fast mode) per OpenAI Responses model.
|
|
45
135
|
- Route each provider directly or through its own HTTP(S) proxy.
|
|
@@ -89,13 +179,16 @@ pi install npm:pi-model-manager
|
|
|
89
179
|
| Key | Action |
|
|
90
180
|
| --- | --- |
|
|
91
181
|
| `Enter` | Open the selected provider and manage its models |
|
|
92
|
-
| `
|
|
93
|
-
| `
|
|
94
|
-
| `
|
|
95
|
-
|
|
|
182
|
+
| `N` | Create a provider and its first model |
|
|
183
|
+
| `D` | Delete the selected provider |
|
|
184
|
+
| `H` | Manage reusable header profiles |
|
|
185
|
+
| `L` | Switch the UI language (Simplified Chinese / English); the choice applies immediately and is saved |
|
|
186
|
+
| `/` | Search the current list; `Tab` leaves the input while keeping the filter, `Esc` clears it |
|
|
96
187
|
| `Esc` | Go back or exit |
|
|
97
188
|
|
|
98
|
-
|
|
189
|
+
Single-letter shortcuts are case-insensitive. The footer hints wrap per item, so they are never truncated away on narrow terminals.
|
|
190
|
+
|
|
191
|
+
4. In an editor, use `↑` / `↓` to select a field and press `Enter` to edit it. Toggle switch fields in place with `←` / `→`, then press `Ctrl+S` to save.
|
|
99
192
|
|
|
100
193
|
Saving updates and enables the model, but it does not force the current session to switch models.
|
|
101
194
|
|
|
@@ -111,10 +204,12 @@ Each provider can define:
|
|
|
111
204
|
|
|
112
205
|
When adding a model, the extension attempts to fetch the upstream model list. The complete discovery flow, including authentication fallbacks, shares one 10-second limit and can be cancelled with `Esc`. You can still enter a model ID manually after failure or cancellation.
|
|
113
206
|
|
|
207
|
+
The base URL is normalized as you enter it into the root address each protocol's SDK expects: OpenAI variants get `/v1` appended, Anthropic has `/v1` stripped, and Google gets `/v1beta` on its official host. A non-root path you type explicitly (such as `https://gw.example.com/custom`) is never rewritten. Switching the API protocol re-normalizes the address for the new protocol. As a result `models.json` always stores the actual request root, so Pi can use it directly even when this extension is not loaded.
|
|
208
|
+
|
|
114
209
|
Model capabilities include:
|
|
115
210
|
|
|
116
211
|
- Display name
|
|
117
|
-
-
|
|
212
|
+
- Vision support (text only, or text + image input)
|
|
118
213
|
- Reasoning support
|
|
119
214
|
- Anthropic Adaptive/Legacy Thinking
|
|
120
215
|
- OpenAI Responses Fast mode
|
|
@@ -132,8 +227,8 @@ Model capabilities include:
|
|
|
132
227
|
|
|
133
228
|
The current built-in values were derived from real client requests with authentication fields removed:
|
|
134
229
|
|
|
135
|
-
- Claude Code `2.1.
|
|
136
|
-
- Codex TUI `0.
|
|
230
|
+
- Claude Code `2.1.232`
|
|
231
|
+
- Codex TUI `0.147.0`
|
|
137
232
|
|
|
138
233
|
These headers only help API gateways that require a recognized client identity; they do not replace an API key. The public repository and npm package contain **no request-capture tooling, user captures, authentication headers, or machine-local state**. Disable identity headers or create a custom profile if a built-in profile does not fit your endpoint.
|
|
139
234
|
|
|
@@ -173,11 +268,11 @@ Additional considerations:
|
|
|
173
268
|
|
|
174
269
|
| Component | Requirement |
|
|
175
270
|
| --- | --- |
|
|
176
|
-
| `@earendil-works/pi-coding-agent` | `>=0.
|
|
271
|
+
| `@earendil-works/pi-coding-agent` | `>=0.84.2` |
|
|
177
272
|
| `@earendil-works/pi-tui` | `>=0.75.0` |
|
|
178
273
|
| Runtime mode | `/model-manager` requires the Pi TUI |
|
|
179
274
|
|
|
180
|
-
The
|
|
275
|
+
The TUI copy defaults to Simplified Chinese; press `L` on the dashboard to switch to English.
|
|
181
276
|
|
|
182
277
|
## Local development
|
|
183
278
|
|
package/README.md
CHANGED
|
@@ -2,44 +2,134 @@
|
|
|
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.
|
|
11
|
+
> 当前稳定版为 `0.3.1`,要求 Pi `>=0.84.2`。
|
|
12
12
|
|
|
13
13
|
## 界面预览
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
下面的界面文本由真实组件渲染得出(终端宽 88 列)。实际使用时列宽会按当前数据收敛,选中行有背景色,各列状态按语义着色。
|
|
16
|
+
|
|
17
|
+
```text
|
|
18
|
+
────────────────────────────────────────────────────────────────────────────────────────
|
|
19
|
+
/model-manager
|
|
20
|
+
4 接入 · 5 模型 · 0 内置抓包 · 0 自定义请求头
|
|
21
|
+
|
|
22
|
+
接入 API 模型 请求头 代理 认证 状态
|
|
23
|
+
❯ OpenAI (openai) Responses 2 Auto→Codex direct env ready
|
|
24
|
+
Claude (claude) Claude 1 ClaudeCode direct env ready
|
|
25
|
+
Gemini (gemini) Gemini 1 Auto→不添加 direct env ready
|
|
26
|
+
Local vLLM (local) Chat 1 Off proxy key ready
|
|
27
|
+
|
|
28
|
+
────────────────────────────────────────────────────────────────────────────────────────
|
|
29
|
+
OpenAI (openai)
|
|
30
|
+
endpoint https://api.openai.com/v1
|
|
31
|
+
proxy direct
|
|
32
|
+
api Responses · headers Auto→Codex · auth env
|
|
33
|
+
models gpt-5.1, gpt-5.1-mini
|
|
34
|
+
|
|
35
|
+
↑↓ 选择 Enter 进入 N 新建接入 D 删除接入 H 请求头 Esc 退出 / 搜索
|
|
36
|
+
────────────────────────────────────────────────────────────────────────────────────────
|
|
37
|
+
```
|
|
16
38
|
|
|
17
39
|
<details>
|
|
18
|
-
<summary
|
|
40
|
+
<summary>展开其余四个界面</summary>
|
|
19
41
|
|
|
20
|
-
###
|
|
42
|
+
### 接入内的模型列表
|
|
21
43
|
|
|
22
|
-
|
|
44
|
+
```text
|
|
45
|
+
────────────────────────────────────────────────────────────────────────────────────────
|
|
46
|
+
/model-manager / OpenAI
|
|
47
|
+
Responses · 2 模型 · headers Auto→Codex · proxy direct · auth env
|
|
48
|
+
endpoint https://api.openai.com/v1
|
|
23
49
|
|
|
24
|
-
|
|
50
|
+
模型 ID 显示名 输入 Thinking 上下文
|
|
51
|
+
❯ gpt-5.1 默认 文本,视觉 开 400K
|
|
52
|
+
gpt-5.1-mini 默认 文本,视觉 开 400K
|
|
25
53
|
|
|
26
|
-
|
|
54
|
+
↑↓ 选择 Enter 编辑模型 A 添加模型 E 编辑接入 D 删除模型 Esc 返回 / 搜索
|
|
55
|
+
────────────────────────────────────────────────────────────────────────────────────────
|
|
56
|
+
```
|
|
27
57
|
|
|
28
|
-
###
|
|
58
|
+
### 接入配置
|
|
29
59
|
|
|
30
|
-
|
|
60
|
+
```text
|
|
61
|
+
────────────────────────────────────────────────────────────────────────────────────────
|
|
62
|
+
编辑接入 openai
|
|
63
|
+
API Responses · 请求头 自动推荐(Auto→Codex)
|
|
64
|
+
接入 ID 必填,且不能与已有或 pi 内置接入重复
|
|
65
|
+
Ctrl+S 保存并同步 models.json;不切换当前会话模型
|
|
66
|
+
|
|
67
|
+
接入 ID openai
|
|
68
|
+
显示名称 OpenAI
|
|
69
|
+
API 协议 OpenAI Responses
|
|
70
|
+
❯ Base URL https://api.openai.com/v1
|
|
71
|
+
本机代理 关闭
|
|
72
|
+
代理地址 关闭时不使用
|
|
73
|
+
API key $OPENAI_API_KEY
|
|
74
|
+
认证头 默认
|
|
75
|
+
请求头 自动推荐(Auto→Codex)
|
|
76
|
+
|
|
77
|
+
↑↓ 选择 ←→ 切换选项 Enter 编辑 Ctrl+S 保存并同步 Esc 返回
|
|
78
|
+
────────────────────────────────────────────────────────────────────────────────────────
|
|
79
|
+
```
|
|
31
80
|
|
|
32
81
|
### 模型能力
|
|
33
82
|
|
|
34
|
-
|
|
83
|
+
```text
|
|
84
|
+
────────────────────────────────────────────────────────────────────────────────────────
|
|
85
|
+
编辑模型 gpt-5.1
|
|
86
|
+
接入 openai · API Responses
|
|
87
|
+
Ctrl+S 保存并启用模型;不切换当前会话模型
|
|
88
|
+
|
|
89
|
+
模型 ID gpt-5.1
|
|
90
|
+
重新拉取 上游模型列表
|
|
91
|
+
显示名称 默认 = 模型 ID
|
|
92
|
+
❯ 视觉支持 开启
|
|
93
|
+
Thinking 开启
|
|
94
|
+
Fast mode 关闭
|
|
95
|
+
上下文窗口 400000
|
|
96
|
+
最大输出 128000
|
|
97
|
+
请求头 跟随接入(Auto→Codex)
|
|
98
|
+
|
|
99
|
+
↑↓ 选择 ←→ 切换选项 Enter 编辑 Ctrl+S 保存并启用 Esc 返回
|
|
100
|
+
────────────────────────────────────────────────────────────────────────────────────────
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### 模型发现
|
|
104
|
+
|
|
105
|
+
```text
|
|
106
|
+
────────────────────────────────────────────────────────────────────────────────────────
|
|
107
|
+
选择模型(openai)
|
|
108
|
+
搜索: <直接输入搜索>
|
|
109
|
+
匹配 9 / 9 · 页码 1 / 2
|
|
110
|
+
|
|
111
|
+
dall-e-3
|
|
112
|
+
gpt-4.1
|
|
113
|
+
gpt-4.1-mini
|
|
114
|
+
❯ gpt-5.1 ← 当前
|
|
115
|
+
gpt-5.1-codex
|
|
116
|
+
gpt-5.1-mini
|
|
117
|
+
o4-mini
|
|
118
|
+
text-embedding-3-large
|
|
119
|
+
|
|
120
|
+
↑↓ 选择 · ←→/PgUp/PgDn 翻页 · 输入搜索 · Backspace 删除 · Enter 确认 · Esc 取消
|
|
121
|
+
────────────────────────────────────────────────────────────────────────────────────────
|
|
122
|
+
```
|
|
35
123
|
|
|
36
124
|
</details>
|
|
125
|
+
|
|
37
126
|
## 功能
|
|
38
127
|
|
|
39
128
|
- 在 `/model-manager` TUI 中新增、编辑和删除接入与模型。
|
|
129
|
+
- 界面默认使用简体中文;可在主面板按 `L` 切换为 English,语言选择会持久保存。
|
|
40
130
|
- 原生支持 `openai-completions`、`openai-responses`、`anthropic-messages` 和 `google-generative-ai`。
|
|
41
131
|
- 从兼容上游拉取模型 ID,也可手动填写模型。
|
|
42
|
-
-
|
|
132
|
+
- 配置上下文窗口、最大输出、视觉支持和 Thinking。
|
|
43
133
|
- 支持 Anthropic Adaptive Thinking 与 Legacy Thinking。
|
|
44
134
|
- 可为 OpenAI Responses 模型启用 `service_tier=priority`(Fast mode)。
|
|
45
135
|
- 为每个接入单独配置直连或 HTTP(S) 代理。
|
|
@@ -89,13 +179,16 @@ pi install npm:pi-model-manager
|
|
|
89
179
|
| 按键 | 操作 |
|
|
90
180
|
| --- | --- |
|
|
91
181
|
| `Enter` | 进入所选接入并管理模型 |
|
|
92
|
-
| `
|
|
93
|
-
| `
|
|
94
|
-
| `
|
|
95
|
-
|
|
|
182
|
+
| `N` | 新建接入及其第一个模型 |
|
|
183
|
+
| `D` | 删除所选接入 |
|
|
184
|
+
| `H` | 管理可复用请求头 |
|
|
185
|
+
| `L` | 切换界面语言(简体中文 / English),选择后立即生效并持久保存 |
|
|
186
|
+
| `/` | 搜索当前列表;`Tab` 退出输入但保留过滤,`Esc` 清空 |
|
|
96
187
|
| `Esc` | 返回或退出 |
|
|
97
188
|
|
|
98
|
-
|
|
189
|
+
单字母快捷键不区分大小写;底部提示按终端宽度折行,窄终端下也不会丢失。
|
|
190
|
+
|
|
191
|
+
4. 在编辑器中使用 `↑` / `↓` 选择字段,按 `Enter` 编辑;开关类字段可用 `←` / `→` 就地切换;按 `Ctrl+S` 保存。
|
|
99
192
|
|
|
100
193
|
保存会更新并启用模型,但不会强制切换当前会话正在使用的模型。
|
|
101
194
|
|
|
@@ -113,12 +206,14 @@ pi install npm:pi-model-manager
|
|
|
113
206
|
|
|
114
207
|
新建模型时,扩展会尝试从上游读取模型列表;整次发现(包括认证回退)共用一个 10 秒上限,可按 `Esc` 手动取消。失败或取消后仍可手动输入模型 ID。
|
|
115
208
|
|
|
209
|
+
Base URL 在填入时就会归一化为各协议 SDK 可直接使用的根地址:OpenAI 系补上 `/v1`,Anthropic 剔除 `/v1`,Google 在官方域名上补 `/v1beta`;你显式填的非根路径(如 `https://gw.example.com/custom`)不会被改写。切换 API 协议时地址会按新协议重新归一化。因此 `models.json` 里存的就是实际请求根地址,本扩展未加载时 Pi 也能直接使用。
|
|
210
|
+
|
|
116
211
|
### 模型能力
|
|
117
212
|
|
|
118
213
|
模型编辑器支持:
|
|
119
214
|
|
|
120
215
|
- 显示名称
|
|
121
|
-
-
|
|
216
|
+
- 视觉支持(仅文本或文本 + 图片输入)
|
|
122
217
|
- Thinking 开关
|
|
123
218
|
- Anthropic Adaptive/Legacy Thinking 协议
|
|
124
219
|
- OpenAI Responses Fast mode
|
|
@@ -136,8 +231,8 @@ pi install npm:pi-model-manager
|
|
|
136
231
|
|
|
137
232
|
当前内置值来自真实客户端请求并已移除认证信息:
|
|
138
233
|
|
|
139
|
-
- Claude Code `2.1.
|
|
140
|
-
- Codex TUI `0.
|
|
234
|
+
- Claude Code `2.1.232`
|
|
235
|
+
- Codex TUI `0.147.0`
|
|
141
236
|
|
|
142
237
|
这些值只用于兼容需要识别客户端身份的 API 中转,不代替 API key。公开仓库和 npm 包**不包含请求捕获工具、用户抓包、认证头或本机状态**。如果内置值不适合你的服务,请关闭身份头或创建自定义请求头。
|
|
143
238
|
|
|
@@ -177,11 +272,11 @@ ${ANTHROPIC_API_KEY}
|
|
|
177
272
|
|
|
178
273
|
| 组件 | 要求 |
|
|
179
274
|
| --- | --- |
|
|
180
|
-
| `@earendil-works/pi-coding-agent` | `>=0.
|
|
275
|
+
| `@earendil-works/pi-coding-agent` | `>=0.84.2` |
|
|
181
276
|
| `@earendil-works/pi-tui` | `>=0.75.0` |
|
|
182
277
|
| 运行模式 | `/model-manager` 需要 Pi TUI |
|
|
183
278
|
|
|
184
|
-
|
|
279
|
+
默认 TUI 文案为简体中文;可在主面板按 `L` 切换为 English。
|
|
185
280
|
|
|
186
281
|
## 本地开发
|
|
187
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
|
}
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
// 模型管理保存边界:锁内重读最新 models.json/state.json,目标化应用 mutation,
|
|
2
2
|
// 再以可恢复事务写入两个文件。registry 刷新在释放文件锁后执行。
|
|
3
3
|
|
|
4
|
-
import type {
|
|
4
|
+
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
5
|
+
|
|
6
|
+
// [喵喵喵]: 保存后只需要刷新模型 registry,不依赖命令上下文的其余能力;
|
|
7
|
+
// 声明成最小契约,session_start 的 ExtensionContext 也能直接复用这些函数。
|
|
8
|
+
type RegistryRefreshContext = Pick<ExtensionContext, "modelRegistry">;
|
|
5
9
|
import { unlink } from "node:fs/promises";
|
|
6
10
|
import { atomicWriteText } from "./atomic-write.ts";
|
|
7
11
|
import { formatUnknownError, isObjectRecord, stringifyJson } from "./common.ts";
|
|
8
12
|
import { withConfigurationLock } from "./configuration-lock.ts";
|
|
9
13
|
import { hashTextContent, readStableTextFileSnapshot } from "./file-snapshot.ts";
|
|
14
|
+
import { t } from "./i18n.ts";
|
|
10
15
|
import {
|
|
11
16
|
MODELS_JSON_PATH,
|
|
12
17
|
markManagedProvidersInDoc,
|
|
@@ -70,18 +75,18 @@ function createTransition(oldSource: string | undefined, targetSource: string):
|
|
|
70
75
|
}
|
|
71
76
|
|
|
72
77
|
function readTransition(raw: unknown, path: string): FileTransition {
|
|
73
|
-
if (!isObjectRecord(raw)) throw new Error(
|
|
78
|
+
if (!isObjectRecord(raw)) throw new Error(t("{path} 必须是对象", { path }));
|
|
74
79
|
const oldSource = raw.oldSource;
|
|
75
80
|
const oldHash = raw.oldHash;
|
|
76
81
|
const targetSource = raw.targetSource;
|
|
77
82
|
const targetHash = raw.targetHash;
|
|
78
|
-
if (oldSource !== null && typeof oldSource !== "string") throw new Error(
|
|
83
|
+
if (oldSource !== null && typeof oldSource !== "string") throw new Error(t("{path}.oldSource 必须是字符串或 null", { path }));
|
|
79
84
|
if (typeof oldHash !== "string" || typeof targetSource !== "string" || typeof targetHash !== "string") {
|
|
80
|
-
throw new Error(
|
|
85
|
+
throw new Error(t("{path} 缺少有效内容或签名", { path }));
|
|
81
86
|
}
|
|
82
87
|
const normalizedOldSource = oldSource === null ? undefined : oldSource;
|
|
83
88
|
if (hashTextContent(normalizedOldSource) !== oldHash || hashTextContent(targetSource) !== targetHash) {
|
|
84
|
-
throw new Error(
|
|
89
|
+
throw new Error(t("{path} 内容签名校验失败", { path }));
|
|
85
90
|
}
|
|
86
91
|
return { oldSource, oldHash, targetSource, targetHash };
|
|
87
92
|
}
|
|
@@ -89,7 +94,7 @@ function readTransition(raw: unknown, path: string): FileTransition {
|
|
|
89
94
|
function parseTransactionJournal(source: string): ConfigurationTransactionJournal {
|
|
90
95
|
const raw = JSON.parse(source);
|
|
91
96
|
if (!isObjectRecord(raw) || raw.version !== 1 || typeof raw.createdAt !== "string") {
|
|
92
|
-
throw new Error("事务意图文件格式无效");
|
|
97
|
+
throw new Error(t("事务意图文件格式无效"));
|
|
93
98
|
}
|
|
94
99
|
return {
|
|
95
100
|
version: 1,
|
|
@@ -111,14 +116,14 @@ async function classifyTransition(path: string, transition: FileTransition): Pro
|
|
|
111
116
|
const current = await readStableTextFileSnapshot(path);
|
|
112
117
|
if (current.contentHash === transition.targetHash) return "target";
|
|
113
118
|
if (current.contentHash === transition.oldHash) return "old";
|
|
114
|
-
throw new Error(
|
|
119
|
+
throw new Error(t("{path} 的当前内容既不是事务旧版本,也不是目标版本;已保留 {transactionPath},不会覆盖外部修改。", { path, transactionPath: TRANSACTION_PATH }));
|
|
115
120
|
}
|
|
116
121
|
|
|
117
122
|
async function finishTransition(path: string, transition: FileTransition, status: "old" | "target"): Promise<void> {
|
|
118
123
|
if (status === "old") await atomicWriteText(path, transition.targetSource);
|
|
119
124
|
const completed = await readStableTextFileSnapshot(path);
|
|
120
125
|
if (completed.contentHash !== transition.targetHash) {
|
|
121
|
-
throw new Error(
|
|
126
|
+
throw new Error(t("{path} 写入后内容签名不匹配;已保留 {transactionPath} 供恢复。", { path, transactionPath: TRANSACTION_PATH }));
|
|
122
127
|
}
|
|
123
128
|
}
|
|
124
129
|
|
|
@@ -129,7 +134,7 @@ async function recoverPendingConfigurationTransactionInsideLock(): Promise<boole
|
|
|
129
134
|
try {
|
|
130
135
|
journal = parseTransactionJournal(journalSnapshot.source);
|
|
131
136
|
} catch (error) {
|
|
132
|
-
throw new Error(
|
|
137
|
+
throw new Error(t("无法解析未完成事务 {transactionPath}:{error}", { transactionPath: TRANSACTION_PATH, error: formatUnknownError(error) }));
|
|
133
138
|
}
|
|
134
139
|
|
|
135
140
|
// 先同时判定两端,任何一端存在外部修改时都不继续写另一端。
|
|
@@ -151,7 +156,7 @@ export async function recoverPendingConfigurationTransaction(): Promise<boolean>
|
|
|
151
156
|
async function assertSnapshotStillCurrent(path: string, expectedHash: string): Promise<void> {
|
|
152
157
|
const current = await readStableTextFileSnapshot(path);
|
|
153
158
|
if (current.contentHash !== expectedHash) {
|
|
154
|
-
throw new Error(
|
|
159
|
+
throw new Error(t("{path} 已被其它进程或编辑器修改;已取消本次保存,请重新打开 /model-manager 后重试。", { path }));
|
|
155
160
|
}
|
|
156
161
|
}
|
|
157
162
|
|
|
@@ -182,7 +187,7 @@ async function writeConfigurationTransaction(
|
|
|
182
187
|
await finishTransition(STATE_PATH, journal.metadataState, metadataStatus);
|
|
183
188
|
await removeTransactionJournal();
|
|
184
189
|
} catch (error) {
|
|
185
|
-
throw new Error(
|
|
190
|
+
throw new Error(t("配置事务未完成:{error}。下次启动或保存会尝试恢复。", { error: formatUnknownError(error) }));
|
|
186
191
|
}
|
|
187
192
|
}
|
|
188
193
|
|
|
@@ -220,7 +225,7 @@ async function persistConfigurationInsideLock(
|
|
|
220
225
|
}
|
|
221
226
|
|
|
222
227
|
async function refreshRegistryAfterPersistence(
|
|
223
|
-
ctx:
|
|
228
|
+
ctx: RegistryRefreshContext,
|
|
224
229
|
persist: () => Promise<StateDocument>,
|
|
225
230
|
): Promise<StateDocument> {
|
|
226
231
|
let document: StateDocument;
|
|
@@ -228,18 +233,18 @@ async function refreshRegistryAfterPersistence(
|
|
|
228
233
|
document = await withConfigurationLock(persist);
|
|
229
234
|
invalidateStateCache();
|
|
230
235
|
} catch (error) {
|
|
231
|
-
throw new Error(
|
|
236
|
+
throw new Error(t("models.json/state.json 未完整保存:{error}", { error: formatUnknownError(error) }));
|
|
232
237
|
}
|
|
233
238
|
try {
|
|
234
239
|
await ctx.modelRegistry.refresh();
|
|
235
240
|
} catch (error) {
|
|
236
|
-
throw new Error(
|
|
241
|
+
throw new Error(t("models.json/state.json 已写入,但当前会话 registry 重载失败:{error}。可执行 /reload 重试。", { error: formatUnknownError(error) }));
|
|
237
242
|
}
|
|
238
243
|
return document;
|
|
239
244
|
}
|
|
240
245
|
|
|
241
246
|
export async function persistManagedConfiguration(
|
|
242
|
-
ctx:
|
|
247
|
+
ctx: RegistryRefreshContext,
|
|
243
248
|
prepare: PrepareConfigurationChange,
|
|
244
249
|
): Promise<StateDocument> {
|
|
245
250
|
return refreshRegistryAfterPersistence(ctx, () => persistConfigurationInsideLock(
|
|
@@ -254,7 +259,7 @@ export async function persistManagedConfiguration(
|
|
|
254
259
|
}
|
|
255
260
|
|
|
256
261
|
export async function persistProviderRenameConfiguration(
|
|
257
|
-
ctx:
|
|
262
|
+
ctx: RegistryRefreshContext,
|
|
258
263
|
prepare: PrepareConfigurationChange,
|
|
259
264
|
oldProviderId: string,
|
|
260
265
|
newProviderId: string,
|
|
@@ -271,7 +276,7 @@ export async function persistProviderRenameConfiguration(
|
|
|
271
276
|
}
|
|
272
277
|
|
|
273
278
|
export async function persistModelConfiguration(
|
|
274
|
-
ctx:
|
|
279
|
+
ctx: RegistryRefreshContext,
|
|
275
280
|
prepare: PrepareConfigurationChange,
|
|
276
281
|
providerId: string,
|
|
277
282
|
modelId: string,
|
|
@@ -288,7 +293,7 @@ export async function persistModelConfiguration(
|
|
|
288
293
|
}
|
|
289
294
|
|
|
290
295
|
export async function persistModelRenameConfiguration(
|
|
291
|
-
ctx:
|
|
296
|
+
ctx: RegistryRefreshContext,
|
|
292
297
|
prepare: PrepareConfigurationChange,
|
|
293
298
|
providerId: string,
|
|
294
299
|
oldModelId: string,
|
|
@@ -307,7 +312,7 @@ export async function persistModelRenameConfiguration(
|
|
|
307
312
|
}
|
|
308
313
|
|
|
309
314
|
export async function persistModelDeletionConfiguration(
|
|
310
|
-
ctx:
|
|
315
|
+
ctx: RegistryRefreshContext,
|
|
311
316
|
prepare: PrepareConfigurationChange,
|
|
312
317
|
providerId: string,
|
|
313
318
|
modelId: string,
|