u1s1-cli 0.12.0 → 0.13.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/dist/agent-setup.d.ts +3 -2
- package/dist/agent-setup.js +5 -6
- package/dist/api.d.ts +16 -0
- package/dist/config.js +1 -1
- package/dist/login.js +25 -3
- package/dist/usage.js +40 -0
- package/package.json +1 -1
package/dist/agent-setup.d.ts
CHANGED
|
@@ -41,8 +41,9 @@ export declare function toProviderModels(models: ModelDef[]): {
|
|
|
41
41
|
}[];
|
|
42
42
|
/**
|
|
43
43
|
* 自定义端点 → pi provider 条目。密钥走环境变量引用(启动器已 set,见
|
|
44
|
-
*
|
|
45
|
-
*
|
|
44
|
+
* endpointKeyEnv),文件里不落明文;没配密钥的端点(本机 Ollama 等)写
|
|
45
|
+
* 字面量 "local" —— pi 没有凭据会直接拒启("No API key found"),
|
|
46
|
+
* 这是 pi 自带 llama provider 的同款兜底,本地服务会忽略 Authorization 头。
|
|
46
47
|
*/
|
|
47
48
|
export declare function endpointProviderEntry(ep: CustomEndpoint): Record<string, unknown>;
|
|
48
49
|
/** 把各端点密钥放进环境(TUI 直接 process.env;web 传给子进程)。 */
|
package/dist/agent-setup.js
CHANGED
|
@@ -147,19 +147,18 @@ export function toProviderModels(models) {
|
|
|
147
147
|
}
|
|
148
148
|
/**
|
|
149
149
|
* 自定义端点 → pi provider 条目。密钥走环境变量引用(启动器已 set,见
|
|
150
|
-
*
|
|
151
|
-
*
|
|
150
|
+
* endpointKeyEnv),文件里不落明文;没配密钥的端点(本机 Ollama 等)写
|
|
151
|
+
* 字面量 "local" —— pi 没有凭据会直接拒启("No API key found"),
|
|
152
|
+
* 这是 pi 自带 llama provider 的同款兜底,本地服务会忽略 Authorization 头。
|
|
152
153
|
*/
|
|
153
154
|
export function endpointProviderEntry(ep) {
|
|
154
|
-
|
|
155
|
+
return {
|
|
155
156
|
name: ep.name,
|
|
156
157
|
baseUrl: ep.baseUrl,
|
|
157
158
|
api: ep.api,
|
|
159
|
+
apiKey: ep.apiKey ? `$${endpointKeyEnvName(ep.id)}` : "local",
|
|
158
160
|
models: toProviderModels(ep.models),
|
|
159
161
|
};
|
|
160
|
-
if (ep.apiKey)
|
|
161
|
-
entry["apiKey"] = `$${endpointKeyEnvName(ep.id)}`;
|
|
162
|
-
return entry;
|
|
163
162
|
}
|
|
164
163
|
/** 把各端点密钥放进环境(TUI 直接 process.env;web 传给子进程)。 */
|
|
165
164
|
export function endpointKeyEnv() {
|
package/dist/api.d.ts
CHANGED
|
@@ -14,6 +14,22 @@ export interface MeResponse {
|
|
|
14
14
|
remaining_usd: number;
|
|
15
15
|
/** USD→默认模型 Token 折算率;老网关没有该字段,展示时需兜底回 $ */
|
|
16
16
|
tokens_per_usd?: number;
|
|
17
|
+
/** 用量包(新网关);老网关没有该字段,展示时退回 daily_free_* 旧口径 */
|
|
18
|
+
packages?: MePackage[];
|
|
19
|
+
/** 可领取的免费包:'first' 首月包 / 'renew' 年度包 / null 已有生效中的 */
|
|
20
|
+
free_claim?: "first" | "renew" | null;
|
|
21
|
+
}
|
|
22
|
+
export interface MePackage {
|
|
23
|
+
id: number;
|
|
24
|
+
kind: string;
|
|
25
|
+
scope: string;
|
|
26
|
+
daily_tokens: number | null;
|
|
27
|
+
total_tokens: number | null;
|
|
28
|
+
used_today: number;
|
|
29
|
+
used_tokens: number;
|
|
30
|
+
remaining: number;
|
|
31
|
+
expires_at: string | null;
|
|
32
|
+
note: string | null;
|
|
17
33
|
}
|
|
18
34
|
export interface ApiModel {
|
|
19
35
|
id: string;
|
package/dist/config.js
CHANGED
package/dist/login.js
CHANGED
|
@@ -74,7 +74,7 @@ async function promptForKey() {
|
|
|
74
74
|
process.exit(1);
|
|
75
75
|
}
|
|
76
76
|
console.log(" 需要一把 API Key(免费):");
|
|
77
|
-
console.log(` 1. 打开 ${DASHBOARD_URL} 注册/登录(30
|
|
77
|
+
console.log(` 1. 打开 ${DASHBOARD_URL} 注册/登录(30 秒,注册领免费用量包:首月每天 1 亿 Token)`);
|
|
78
78
|
console.log(" 2. 复制你的 API Key,粘贴到下面");
|
|
79
79
|
console.log("");
|
|
80
80
|
tryOpenBrowser(DASHBOARD_URL);
|
|
@@ -91,7 +91,7 @@ export async function login(keyArg) {
|
|
|
91
91
|
const origin = apiOrigin(cfg);
|
|
92
92
|
const start = await startDeviceLogin(origin);
|
|
93
93
|
if (start) {
|
|
94
|
-
console.log(" 用浏览器登录(
|
|
94
|
+
console.log(" 用浏览器登录(注册领免费用量包,首月每天 1 亿 Token):");
|
|
95
95
|
console.log("");
|
|
96
96
|
console.log(` ${start.verify_url}`);
|
|
97
97
|
console.log("");
|
|
@@ -119,7 +119,29 @@ export async function login(keyArg) {
|
|
|
119
119
|
process.exit(1);
|
|
120
120
|
});
|
|
121
121
|
saveConfig(next);
|
|
122
|
-
|
|
122
|
+
const tpu = me.tokens_per_usd ?? 0;
|
|
123
|
+
let quotaNote;
|
|
124
|
+
if (me.free_claim) {
|
|
125
|
+
// 新网关且免费包可领/可续,登录成功时顺手提醒
|
|
126
|
+
quotaNote =
|
|
127
|
+
me.free_claim === "first"
|
|
128
|
+
? "免费用量包还没领,去 https://u1s1.io/dashboard 点「领取」(首月每天 1 亿 Token)"
|
|
129
|
+
: "免费用量包到期了,去 https://u1s1.io/dashboard 续领(每天 5000 万 Token)";
|
|
130
|
+
}
|
|
131
|
+
else if (tpu > 0) {
|
|
132
|
+
const tok = (usd) => {
|
|
133
|
+
const t = usd * tpu;
|
|
134
|
+
if (t >= 1e8)
|
|
135
|
+
return `${Math.round((t / 1e8) * 10) / 10} 亿`;
|
|
136
|
+
return `${Math.round(t / 1e4).toLocaleString("en-US")} 万`;
|
|
137
|
+
};
|
|
138
|
+
quotaNote = `今日免费还剩约 ${tok(me.daily_free_remaining_usd)} Token`;
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
// 老网关:没有 tokens_per_usd,退回金额显示
|
|
142
|
+
quotaNote = `今日免费还剩 $${me.daily_free_remaining_usd},永久余额 $${me.remaining_usd}`;
|
|
143
|
+
}
|
|
144
|
+
console.log(` ✓ 登录成功${me.email ? `(${me.email})` : ""},${quotaNote}。`);
|
|
123
145
|
return next;
|
|
124
146
|
}
|
|
125
147
|
/** Returns a config that definitely has an apiKey, prompting the user if needed. */
|
package/dist/usage.js
CHANGED
|
@@ -35,6 +35,46 @@ export async function usage() {
|
|
|
35
35
|
const tpu = me.tokens_per_usd ?? 0;
|
|
36
36
|
console.log("");
|
|
37
37
|
console.log(` 账号 ${me.email ?? "(未绑定邮箱)"}`);
|
|
38
|
+
if (me.packages) {
|
|
39
|
+
// 新网关:按用量包逐个展示,token 原生数字
|
|
40
|
+
const PKG_LABEL = {
|
|
41
|
+
free_first: "首月免费包",
|
|
42
|
+
free_yearly: "年度免费包",
|
|
43
|
+
invite: "邀请赠送",
|
|
44
|
+
topup_daily: "每日加量包",
|
|
45
|
+
admin_grant: "官方赠送",
|
|
46
|
+
};
|
|
47
|
+
if (me.packages.length === 0)
|
|
48
|
+
console.log(" 用量包 (无生效中的用量包)");
|
|
49
|
+
for (const p of me.packages) {
|
|
50
|
+
const daily = p.daily_tokens != null;
|
|
51
|
+
const total = daily ? (p.daily_tokens ?? 0) : (p.total_tokens ?? 0);
|
|
52
|
+
const ratio = total > 0 ? p.remaining / total : 0;
|
|
53
|
+
const label = (PKG_LABEL[p.kind] ?? p.kind).padEnd(5, " ");
|
|
54
|
+
const per = daily ? "/天" : "";
|
|
55
|
+
console.log(` ${label} 还剩 ${fmtTokensCn(p.remaining)} / ${fmtTokensCn(total)}${per} ${bar(ratio)}`);
|
|
56
|
+
const scopeNote = p.scope === "free" ? "仅默认模型和搜索 · 0 点恢复" : "全模型可用";
|
|
57
|
+
console.log(` ${scopeNote} · ${p.expires_at ? `${p.expires_at.slice(0, 10)} 到期` : "永不过期"}`);
|
|
58
|
+
}
|
|
59
|
+
if (me.bonus_balance_usd > 0) {
|
|
60
|
+
const balText = tpu > 0 ? `${fmtTokensCn(me.bonus_balance_usd * tpu)} Token` : `$${me.bonus_balance_usd}`;
|
|
61
|
+
console.log(` 余额(按量) ${balText}`);
|
|
62
|
+
}
|
|
63
|
+
console.log(` 本月已用 约 ${tpu > 0 ? `${fmtTokensCn(me.mtd_usd * tpu)} Token` : ""}($${me.mtd_usd.toFixed(2)})`);
|
|
64
|
+
console.log("");
|
|
65
|
+
if (me.free_claim === "first") {
|
|
66
|
+
console.log(" → 你有免费用量包没领:首月每天 1 亿 Token,去 https://u1s1.io/dashboard 点「领取」");
|
|
67
|
+
}
|
|
68
|
+
else if (me.free_claim === "renew") {
|
|
69
|
+
console.log(" → 免费用量包到期了,去 https://u1s1.io/dashboard 续领:每天 5000 万 Token,一年有效");
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
console.log(" 免费包每天 0 点恢复;邀请朋友双方各得一次性 1 亿 Token 包 → https://u1s1.io/dashboard");
|
|
73
|
+
}
|
|
74
|
+
console.log(" Token 数按默认模型单价折算,为约数;用更贵的模型时消耗更快。");
|
|
75
|
+
console.log("");
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
38
78
|
if (tpu > 0) {
|
|
39
79
|
const tok = (usd) => `${fmtTokensCn(usd * tpu)} Token`;
|
|
40
80
|
console.log(` 今日免费 还剩 ${fmtTokensCn(freeRemain * tpu)} / ${tok(freeTotal)} ${bar(freeRatio)}`);
|