@wax0629/pi-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 +21 -0
- package/README.md +93 -0
- package/package.json +51 -0
- package/src/cli.mjs +155 -0
- package/src/defaults.mjs +215 -0
- package/src/gateway.mjs +199 -0
- package/src/pi-apply.mjs +230 -0
- package/src/pi-auth.mjs +109 -0
- package/src/pi-import.mjs +120 -0
- package/src/pi-native.mjs +239 -0
- package/src/profile.mjs +225 -0
- package/src/provider-discovery.mjs +146 -0
- package/src/provider-test.mjs +178 -0
- package/src/secrets.mjs +123 -0
- package/src/server.mjs +761 -0
- package/src/store.mjs +615 -0
- package/src/thinking.mjs +107 -0
- package/web/README.md +32 -0
- package/web/dist/assets/index-CW8mUwad.js +9 -0
- package/web/dist/assets/index-Dnr7dLeF.css +2 -0
- package/web/dist/favicon.svg +1 -0
- package/web/dist/icons.svg +24 -0
- package/web/dist/index.html +17 -0
package/src/thinking.mjs
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
export const PI_THINKING_LEVELS = Object.freeze([
|
|
2
|
+
"off",
|
|
3
|
+
"minimal",
|
|
4
|
+
"low",
|
|
5
|
+
"medium",
|
|
6
|
+
"high",
|
|
7
|
+
"xhigh",
|
|
8
|
+
"max"
|
|
9
|
+
]);
|
|
10
|
+
|
|
11
|
+
export const THINKING_MAP_SOURCES = Object.freeze([
|
|
12
|
+
"provider-default",
|
|
13
|
+
"provider-docs",
|
|
14
|
+
"request-probe",
|
|
15
|
+
"user"
|
|
16
|
+
]);
|
|
17
|
+
|
|
18
|
+
const extendedThinkingLevels = new Set(["xhigh", "max"]);
|
|
19
|
+
|
|
20
|
+
function hasOwn(value, key) {
|
|
21
|
+
return Object.prototype.hasOwnProperty.call(value, key);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function isRecord(value) {
|
|
25
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function buildThinkingLevelMap({ reasoning, thinkingLevels = [] }) {
|
|
29
|
+
if (!reasoning) return { off: "none" };
|
|
30
|
+
|
|
31
|
+
const supported = new Set(thinkingLevels);
|
|
32
|
+
const map = { off: "none" };
|
|
33
|
+
for (const level of PI_THINKING_LEVELS) {
|
|
34
|
+
if (level === "off") continue;
|
|
35
|
+
map[level] = supported.has(level) ? level : null;
|
|
36
|
+
}
|
|
37
|
+
return map;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function normalizeThinkingLevelMap(value, { reasoning = true, thinkingLevels } = {}) {
|
|
41
|
+
if (!reasoning) return { off: "none" };
|
|
42
|
+
|
|
43
|
+
if (value !== undefined) {
|
|
44
|
+
if (!isRecord(value)) return {};
|
|
45
|
+
const normalized = {};
|
|
46
|
+
for (const [level, mapped] of Object.entries(value)) {
|
|
47
|
+
if (!PI_THINKING_LEVELS.includes(level)) continue;
|
|
48
|
+
if (mapped === null) normalized[level] = null;
|
|
49
|
+
else if (typeof mapped === "string" && mapped.trim()) normalized[level] = mapped.trim();
|
|
50
|
+
}
|
|
51
|
+
return normalized;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (Array.isArray(thinkingLevels)) return buildThinkingLevelMap({ reasoning, thinkingLevels });
|
|
55
|
+
return {};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function validateThinkingLevelMap(value, { reasoning = true } = {}) {
|
|
59
|
+
if (!isRecord(value)) throw new Error("Thinking 映射必须是对象");
|
|
60
|
+
|
|
61
|
+
const normalized = {};
|
|
62
|
+
for (const [level, mapped] of Object.entries(value)) {
|
|
63
|
+
if (!PI_THINKING_LEVELS.includes(level)) throw new Error(`未知 Thinking 等级: ${level}`);
|
|
64
|
+
if (mapped !== null && (typeof mapped !== "string" || !mapped.trim())) {
|
|
65
|
+
throw new Error(`${level} 的上游值必须是非空字符串或 null`);
|
|
66
|
+
}
|
|
67
|
+
normalized[level] = mapped === null ? null : mapped.trim();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (!reasoning) {
|
|
71
|
+
for (const [level, mapped] of Object.entries(normalized)) {
|
|
72
|
+
if (level !== "off" && mapped !== null) throw new Error("非 reasoning 模型只能配置 off");
|
|
73
|
+
}
|
|
74
|
+
if (normalized.off === null) throw new Error("非 reasoning 模型必须保留 off");
|
|
75
|
+
return { off: normalized.off || "none" };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return normalized;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function normalizeThinkingMapSource(value) {
|
|
82
|
+
return THINKING_MAP_SOURCES.includes(value) ? value : "provider-default";
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function getSupportedThinkingLevels(model) {
|
|
86
|
+
if (!model?.reasoning) return ["off"];
|
|
87
|
+
const map = model.thinkingLevelMap || {};
|
|
88
|
+
return PI_THINKING_LEVELS.filter((level) => {
|
|
89
|
+
if (hasOwn(map, level)) return map[level] !== null;
|
|
90
|
+
return !extendedThinkingLevels.has(level);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function getThinkingLevelValue(model, level) {
|
|
95
|
+
if (!PI_THINKING_LEVELS.includes(level)) return undefined;
|
|
96
|
+
const map = model?.thinkingLevelMap || {};
|
|
97
|
+
if (hasOwn(map, level)) return map[level];
|
|
98
|
+
return extendedThinkingLevels.has(level) ? null : undefined;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function assertSupportedThinkingLevel(model, level) {
|
|
102
|
+
const normalizedLevel = String(level || "");
|
|
103
|
+
if (getSupportedThinkingLevels(model).includes(normalizedLevel)) return normalizedLevel;
|
|
104
|
+
const available = getSupportedThinkingLevels(model).join(" / ") || "无可用等级";
|
|
105
|
+
throw new Error(`模型 ${model?.id || "(unknown)"} 不支持 Thinking: ${normalizedLevel || "(empty)"};可用:${available}`);
|
|
106
|
+
}
|
|
107
|
+
|
package/web/README.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# React + TypeScript + Vite
|
|
2
|
+
|
|
3
|
+
This template provides a minimal setup to get React working in Vite with HMR and some Oxlint rules.
|
|
4
|
+
|
|
5
|
+
Currently, two official plugins are available:
|
|
6
|
+
|
|
7
|
+
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Oxc](https://oxc.rs)
|
|
8
|
+
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/)
|
|
9
|
+
|
|
10
|
+
## React Compiler
|
|
11
|
+
|
|
12
|
+
The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
|
|
13
|
+
|
|
14
|
+
## Expanding the Oxlint configuration
|
|
15
|
+
|
|
16
|
+
If you are developing a production application, we recommend enabling type-aware lint rules by installing `oxlint-tsgolint` and editing `.oxlintrc.json`:
|
|
17
|
+
|
|
18
|
+
```json
|
|
19
|
+
{
|
|
20
|
+
"$schema": "./node_modules/oxlint/configuration_schema.json",
|
|
21
|
+
"plugins": ["react", "typescript", "oxc"],
|
|
22
|
+
"options": {
|
|
23
|
+
"typeAware": true
|
|
24
|
+
},
|
|
25
|
+
"rules": {
|
|
26
|
+
"react/rules-of-hooks": "error",
|
|
27
|
+
"react/only-export-components": ["warn", { "allowConstantExport": true }]
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
See the [Oxlint rules documentation](https://oxc.rs/docs/guide/usage/linter/rules) for the full list of rules and categories.
|