pi-model-manager 0.1.0
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/LICENSE +661 -0
- package/NOTICE +8 -0
- package/README.en.md +206 -0
- package/README.md +210 -0
- package/atomic-write.ts +100 -0
- package/builtin-model-catalog.ts +92 -0
- package/claude-code-compat.ts +56 -0
- package/common.ts +66 -0
- package/compat-settings.ts +25 -0
- package/config-value-reference.ts +51 -0
- package/configuration-persistence.ts +72 -0
- package/header-profile-mutations.ts +46 -0
- package/index.ts +82 -0
- package/local-proxy-service.ts +313 -0
- package/model-mutations.ts +210 -0
- package/models-json-manager.ts +238 -0
- package/models-json-mutations.ts +90 -0
- package/models-json-sync.ts +386 -0
- package/openai-responses-payload.ts +80 -0
- package/openai-service-tier.ts +36 -0
- package/package.json +74 -0
- package/presets/builtin-client-headers.ts +23 -0
- package/presets/client-headers.ts +126 -0
- package/presets/providers.ts +80 -0
- package/presets/thinking.ts +81 -0
- package/provider-registrar.ts +281 -0
- package/request-pipeline.ts +88 -0
- package/rescue.ts +69 -0
- package/runtime-base-url.ts +54 -0
- package/state-cache.ts +55 -0
- package/state-document.ts +569 -0
- package/state-metadata-store.ts +455 -0
- package/state-store.ts +238 -0
- package/tui/dashboard.ts +376 -0
- package/tui/editor-model.ts +339 -0
- package/tui/editor-provider.ts +219 -0
- package/tui/header-profiles-panel.ts +307 -0
- package/tui/model-list-fetch.ts +259 -0
- package/tui/model-picker.ts +266 -0
- package/tui/models-json-panel.ts +269 -0
- package/tui/persistent-menu.ts +349 -0
- package/tui/ui-helpers.ts +289 -0
- package/types.ts +165 -0
package/types.ts
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
// pi-model-manager 类型定义。
|
|
2
|
+
// 命名约定:
|
|
3
|
+
// Stored* → models.json 与 state.json metadata 合成后的运行时视图
|
|
4
|
+
// *Draft → TUI 编辑器中可变中间态
|
|
5
|
+
// *Outcome → 异步流程结果联合类型
|
|
6
|
+
|
|
7
|
+
// ========== 基础枚举 ==========
|
|
8
|
+
|
|
9
|
+
export type ApiKind = "openai-completions" | "openai-responses" | "anthropic-messages" | "google-generative-ai";
|
|
10
|
+
export type ModelInputKind = "text" | "image";
|
|
11
|
+
export type ThinkingLevel = "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
|
|
12
|
+
export type ThinkingLevelMap = Partial<Record<ThinkingLevel, string | null>>;
|
|
13
|
+
export type ReasoningMode = "enabled" | "disabled";
|
|
14
|
+
export type AnthropicThinkingProtocol = "adaptive" | "legacy";
|
|
15
|
+
export type BuiltInClientHeaderProfileId = "claude-code" | "codex-cli";
|
|
16
|
+
export type ClientHeaderProfileId = "recommended" | "disabled" | BuiltInClientHeaderProfileId | "custom";
|
|
17
|
+
export type CompatSettings = Record<string, unknown>;
|
|
18
|
+
export type OpenAIServiceTier = "priority";
|
|
19
|
+
|
|
20
|
+
export const DEFAULT_PROVIDER_HTTP_PROXY_URL = "http://127.0.0.1:7890";
|
|
21
|
+
|
|
22
|
+
// ========== 持久配置合成 schema ==========
|
|
23
|
+
|
|
24
|
+
export interface TokenCostTier {
|
|
25
|
+
inputTokensAbove: number;
|
|
26
|
+
input: number;
|
|
27
|
+
output: number;
|
|
28
|
+
cacheRead: number;
|
|
29
|
+
cacheWrite: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface TokenCost {
|
|
33
|
+
input: number;
|
|
34
|
+
output: number;
|
|
35
|
+
cacheRead: number;
|
|
36
|
+
cacheWrite: number;
|
|
37
|
+
tiers?: TokenCostTier[];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface StoredRequestHeaderProfile {
|
|
41
|
+
name: string;
|
|
42
|
+
headers: Record<string, string>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface StoredClientHeaderCapture {
|
|
46
|
+
capturedAt: string;
|
|
47
|
+
headers: Record<string, string>;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface StoredModel {
|
|
51
|
+
id: string;
|
|
52
|
+
/** 仅保存相对 provider 默认值的显式模型级覆盖。 */
|
|
53
|
+
api?: string;
|
|
54
|
+
baseUrl?: string;
|
|
55
|
+
/** 不含插件请求头 profile 所管理字段的原生模型请求头。 */
|
|
56
|
+
headers?: Record<string, string>;
|
|
57
|
+
name?: string;
|
|
58
|
+
reasoning: boolean;
|
|
59
|
+
thinkingLevelMap?: ThinkingLevelMap;
|
|
60
|
+
input: ModelInputKind[];
|
|
61
|
+
contextWindow: number;
|
|
62
|
+
maxTokens: number;
|
|
63
|
+
cost: TokenCost;
|
|
64
|
+
/** 旧版模型级请求头字段,仅用于读取旧 state 后折叠到接入级。 */
|
|
65
|
+
clientHeaderProfile?: ClientHeaderProfileId;
|
|
66
|
+
requestHeaderProfileId?: string;
|
|
67
|
+
customClientHeaders?: Record<string, string>;
|
|
68
|
+
openAIServiceTier?: OpenAIServiceTier;
|
|
69
|
+
compat?: CompatSettings;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface StoredProvider {
|
|
73
|
+
name: string;
|
|
74
|
+
api: ApiKind;
|
|
75
|
+
baseUrl: string;
|
|
76
|
+
/** 可省略;认证也可由 auth.json、/login 或 CLI --api-key 提供。 */
|
|
77
|
+
apiKey?: string;
|
|
78
|
+
/** models.json 中不由 TUI 编辑、但必须跨保存和重命名保真的原生字段。 */
|
|
79
|
+
headers?: Record<string, string>;
|
|
80
|
+
compat?: CompatSettings;
|
|
81
|
+
modelOverrides?: Record<string, unknown>;
|
|
82
|
+
authHeader?: boolean;
|
|
83
|
+
clientHeaderProfile: ClientHeaderProfileId;
|
|
84
|
+
requestHeaderProfileId?: string;
|
|
85
|
+
customClientHeaders?: Record<string, string>;
|
|
86
|
+
httpProxyEnabled?: boolean;
|
|
87
|
+
httpProxyUrl?: string;
|
|
88
|
+
models: StoredModel[];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface StateDocument {
|
|
92
|
+
version: 1;
|
|
93
|
+
providers: Record<string, StoredProvider>;
|
|
94
|
+
requestHeaderProfiles: Record<string, StoredRequestHeaderProfile>;
|
|
95
|
+
clientHeaderCaptures: Partial<Record<BuiltInClientHeaderProfileId, StoredClientHeaderCapture>>;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// ========== TUI draft(可变中间态) ==========
|
|
99
|
+
|
|
100
|
+
export interface ProviderDraft {
|
|
101
|
+
providerId: string;
|
|
102
|
+
providerName: string;
|
|
103
|
+
api: ApiKind;
|
|
104
|
+
baseUrl: string;
|
|
105
|
+
apiKey: string;
|
|
106
|
+
authHeader: boolean;
|
|
107
|
+
clientHeaderProfile: ClientHeaderProfileId;
|
|
108
|
+
requestHeaderProfileId?: string;
|
|
109
|
+
customClientHeaders: Record<string, string>;
|
|
110
|
+
httpProxyEnabled: boolean;
|
|
111
|
+
httpProxyUrl: string;
|
|
112
|
+
selectedIndex: number;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export interface ModelDraft {
|
|
116
|
+
providerId: string;
|
|
117
|
+
providerName: string;
|
|
118
|
+
api: ApiKind;
|
|
119
|
+
baseUrl: string;
|
|
120
|
+
apiKey: string;
|
|
121
|
+
authHeader: boolean;
|
|
122
|
+
clientHeaderProfile: ClientHeaderProfileId;
|
|
123
|
+
requestHeaderProfileId?: string;
|
|
124
|
+
customClientHeaders: Record<string, string>;
|
|
125
|
+
httpProxyEnabled: boolean;
|
|
126
|
+
httpProxyUrl: string;
|
|
127
|
+
modelId: string;
|
|
128
|
+
modelName: string;
|
|
129
|
+
inputKinds: ModelInputKind[];
|
|
130
|
+
reasoningMode: ReasoningMode;
|
|
131
|
+
anthropicThinkingProtocol?: AnthropicThinkingProtocol;
|
|
132
|
+
contextWindow: number;
|
|
133
|
+
maxTokens: number;
|
|
134
|
+
openAIServiceTier?: OpenAIServiceTier;
|
|
135
|
+
selectedIndex: number;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export interface RequestHeaderProfileDraft {
|
|
139
|
+
profileId: string;
|
|
140
|
+
profileName: string;
|
|
141
|
+
headers: Record<string, string>;
|
|
142
|
+
selectedIndex: number;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// ========== 异步流程结果 ==========
|
|
146
|
+
|
|
147
|
+
export type ModelListFetchOutcome =
|
|
148
|
+
| { status: "loaded"; modelIds: string[] }
|
|
149
|
+
| { status: "failed"; message: string };
|
|
150
|
+
|
|
151
|
+
export type ModelSelectionOutcome =
|
|
152
|
+
| { status: "selected"; modelId: string }
|
|
153
|
+
| { status: "manual"; fallback: string }
|
|
154
|
+
| { status: "cancelled" };
|
|
155
|
+
|
|
156
|
+
export type DashboardAction =
|
|
157
|
+
| { type: "new-provider" }
|
|
158
|
+
| { type: "provider-menu"; providerId: string }
|
|
159
|
+
| { type: "model-menu"; providerId: string; modelId: string }
|
|
160
|
+
| { type: "open-models-json" }
|
|
161
|
+
| { type: "cancel" };
|
|
162
|
+
|
|
163
|
+
// ========== 常量 ==========
|
|
164
|
+
|
|
165
|
+
export const ZERO_COST: TokenCost = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 };
|