custom-provider-pi 0.1.6 → 0.1.7
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/custom-provider.ts +16 -16
- package/package.json +1 -1
package/custom-provider.ts
CHANGED
|
@@ -36,10 +36,10 @@ const UA_PRESETS: Record<string, string> = {
|
|
|
36
36
|
|
|
37
37
|
// 请求头模板(借鉴 LiveAgent:按客户端/CLI 预设整组请求头,而非只预设 UA):
|
|
38
38
|
// 不同客户端携带的头集合不同(Claude Code 有 x-app/anthropic-version/X-Stainless-* 等)。
|
|
39
|
-
//
|
|
39
|
+
// Apply template headers; or select"custom"逐头输入。
|
|
40
40
|
interface HeaderPreset {
|
|
41
41
|
label: string;
|
|
42
|
-
key?: string; // undefined =
|
|
42
|
+
key?: string; // undefined = custom
|
|
43
43
|
headers: Record<string, string>;
|
|
44
44
|
}
|
|
45
45
|
const HEADER_PRESETS: HeaderPreset[] = [
|
|
@@ -69,7 +69,7 @@ const HEADER_PRESETS: HeaderPreset[] = [
|
|
|
69
69
|
headers: { "User-Agent": UA_PRESETS.openwebui, "accept": "application/json" },
|
|
70
70
|
},
|
|
71
71
|
{ label: "ChatGPT Desktop", key: "chatgpt", headers: { "User-Agent": UA_PRESETS.chatgpt } },
|
|
72
|
-
{ label: "
|
|
72
|
+
{ label: "custom(逐头输入)", key: undefined, headers: {} },
|
|
73
73
|
];
|
|
74
74
|
|
|
75
75
|
// 头名校验:HTTP token 字符集(含 ASCII 特殊符号,无空格/换行)
|
|
@@ -91,8 +91,8 @@ function hasHeader(headers: Record<string, string> | undefined, name: string): b
|
|
|
91
91
|
// ---- 远程规格查询(OpenRouter 公开目录,带磁盘缓存)----
|
|
92
92
|
|
|
93
93
|
// 输出上限处置(借鉴 LiveAgent normalizeModelLimits)
|
|
94
|
-
//
|
|
95
|
-
// 照单全收会把"
|
|
94
|
+
// Community catalogs may provide degraded values for models"output==window",
|
|
95
|
+
// 照单全收会把"window-output-reserve"的输入预算挤成零。处理:钳到保守上限,
|
|
96
96
|
// 并保底留 3/4 窗口给输入。
|
|
97
97
|
const MAX_OUTPUT_TOKEN_CAP = 32000;
|
|
98
98
|
|
|
@@ -1265,10 +1265,10 @@ export default function customProviderExtension(pi: ExtensionAPI) {
|
|
|
1265
1265
|
}
|
|
1266
1266
|
}
|
|
1267
1267
|
|
|
1268
|
-
// ---- 选择添加方式:简单(自动探测+模型)/
|
|
1268
|
+
// ---- 选择添加方式:简单(自动探测+模型)/ custom(完整配置)----
|
|
1269
1269
|
const addMode = await ctx.ui.select(
|
|
1270
1270
|
"添加方式?",
|
|
1271
|
-
["简单添加(自动探测协议 + 模型列表)", "
|
|
1271
|
+
["简单添加(自动探测协议 + 模型列表)", "custom配置(代理/LB/请求头模板/高级选项)"]
|
|
1272
1272
|
);
|
|
1273
1273
|
if (!addMode) return;
|
|
1274
1274
|
|
|
@@ -1335,7 +1335,7 @@ export default function customProviderExtension(pi: ExtensionAPI) {
|
|
|
1335
1335
|
return;
|
|
1336
1336
|
}
|
|
1337
1337
|
|
|
1338
|
-
// =================
|
|
1338
|
+
// ================= custom配置路径(完整向导 2-10 步)=================
|
|
1339
1339
|
// ---- 2. 端点 ----
|
|
1340
1340
|
const baseUrl = await ctx.ui.input(
|
|
1341
1341
|
"API 端点 URL(完整地址,通常含 /v1;粘贴 /v1/models 也会被自动清理)",
|
|
@@ -1370,7 +1370,7 @@ export default function customProviderExtension(pi: ExtensionAPI) {
|
|
|
1370
1370
|
|
|
1371
1371
|
// ---- 4. 协议类型 ----
|
|
1372
1372
|
const apiType = await ctx.ui.select(
|
|
1373
|
-
"API
|
|
1373
|
+
"API protocol type (auto-detect recommended)",
|
|
1374
1374
|
["自动推断", "openai-completions", "openai-responses", "anthropic-messages", "google-generative-ai"]
|
|
1375
1375
|
);
|
|
1376
1376
|
if (!apiType) return;
|
|
@@ -1438,7 +1438,7 @@ export default function customProviderExtension(pi: ExtensionAPI) {
|
|
|
1438
1438
|
"若服务支持模型列表端点可自动获取;否则将手动输入"
|
|
1439
1439
|
);
|
|
1440
1440
|
|
|
1441
|
-
// ---- 6. 请求头模板(预设整组请求头,不同 CLI 头集合不同;选"
|
|
1441
|
+
// ---- 6. 请求头模板(预设整组请求头,不同 CLI 头集合不同;选"custom"逐头输入)----
|
|
1442
1442
|
const presetLabels = HEADER_PRESETS.map((p) => p.label);
|
|
1443
1443
|
const presetChoice = await ctx.ui.select(
|
|
1444
1444
|
"请求头模板?",
|
|
@@ -1477,9 +1477,9 @@ export default function customProviderExtension(pi: ExtensionAPI) {
|
|
|
1477
1477
|
);
|
|
1478
1478
|
} // 浏览器模板 = 不写头,由 pi 自动补充浏览器 UA
|
|
1479
1479
|
} else {
|
|
1480
|
-
//
|
|
1480
|
+
// custom:JSON 对象,或每行 "Key: Value"(值支持 $ENV)
|
|
1481
1481
|
const headersInput = await ctx.ui.input(
|
|
1482
|
-
'
|
|
1482
|
+
'custom请求头(JSON 对象,或每行 "Key: Value":值支持 $ENV;留空取消)',
|
|
1483
1483
|
'{"X-API-Key": "$MY_API_KEY"}'
|
|
1484
1484
|
);
|
|
1485
1485
|
if (headersInput && headersInput.trim()) {
|
|
@@ -1487,7 +1487,7 @@ export default function customProviderExtension(pi: ExtensionAPI) {
|
|
|
1487
1487
|
try {
|
|
1488
1488
|
const parsed = JSON.parse(t);
|
|
1489
1489
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
1490
|
-
applyHeaderSet({ ...parsed }, "
|
|
1490
|
+
applyHeaderSet({ ...parsed }, "custom请求头");
|
|
1491
1491
|
} else {
|
|
1492
1492
|
ctx.ui.notify("JSON 需为对象({...})", "error");
|
|
1493
1493
|
}
|
|
@@ -1507,13 +1507,13 @@ export default function customProviderExtension(pi: ExtensionAPI) {
|
|
|
1507
1507
|
}
|
|
1508
1508
|
kv[line.slice(0, idx).trim()] = line.slice(idx + 1).trim();
|
|
1509
1509
|
}
|
|
1510
|
-
if (parseOk) applyHeaderSet(kv, "
|
|
1510
|
+
if (parseOk) applyHeaderSet(kv, "custom请求头");
|
|
1511
1511
|
}
|
|
1512
1512
|
}
|
|
1513
1513
|
}
|
|
1514
1514
|
}
|
|
1515
1515
|
|
|
1516
|
-
// ---- 7.
|
|
1516
|
+
// ---- 7. 补充/覆盖请求头(在模板/custom基础上追加,可覆盖;无需直接跳过)----
|
|
1517
1517
|
const needMore = await ctx.ui.confirm(
|
|
1518
1518
|
"需要补充/覆盖请求头吗?",
|
|
1519
1519
|
"在现有头部上追加或覆盖(如 X-API-Key),值支持 $ENV 插值"
|
|
@@ -2442,7 +2442,7 @@ export default function customProviderExtension(pi: ExtensionAPI) {
|
|
|
2442
2442
|
description: "管理第三方 Provider:add / remove / refresh / list / test / help",
|
|
2443
2443
|
getArgumentCompletions: (prefix: string) => {
|
|
2444
2444
|
// 注意: pi 会用 item.value 替换整个参数段(命令名后的全部文本),
|
|
2445
|
-
//
|
|
2445
|
+
// So value must be"subcommand + full-name"的完整参数,label 才是用于显示的名称。
|
|
2446
2446
|
const trimmed = prefix.trim();
|
|
2447
2447
|
const match = trimmed.match(/^(\S+)(?:\s+(.*))?$/);
|
|
2448
2448
|
const first = (match?.[1] ?? "").toLowerCase();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "custom-provider-pi",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "pi 扩展:统一管理第三方模型 Provider。子命令体系 /custom-provider add|remove|refresh|list|test|config|enable|disable|prune,支持交互向导、flags/JSON 非交互添加、双协议混用(OpenAI + Anthropic)、模型关键字过滤与修剪、per-provider 代理配置、负载均衡",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|