u1s1-cli 0.19.2 → 0.19.4
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 +8 -0
- package/dist/agent-setup.js +21 -0
- package/dist/index.js +3 -1
- package/dist/usage.js +18 -1
- package/dist/web.js +3 -1
- package/package.json +3 -3
package/dist/agent-setup.d.ts
CHANGED
|
@@ -26,6 +26,14 @@ export declare function writeWebToolsExtension(cfg: CliConfig, features: {
|
|
|
26
26
|
webFetchRender: boolean;
|
|
27
27
|
imageGen: boolean;
|
|
28
28
|
}): void;
|
|
29
|
+
/**
|
|
30
|
+
* 生成「OpenRouter 应用归因」扩展到 <agentDir>/extensions/u1s1-attribution.js。
|
|
31
|
+
* 用户自己配 OPENROUTER_API_KEY 直连时,pi 内置的归因头归到 pi.dev 名下(且受遥测
|
|
32
|
+
* 开关控制);这里用 before_provider_headers 钩子覆盖为 u1s1,让这部分流量也计入
|
|
33
|
+
* u1s1 的 OpenRouter 公开排行与数据分析(openrouter.ai/docs/app-attribution)。
|
|
34
|
+
* 只在请求目标确认为 OpenRouter 时才改头,其它供应商不加多余头。
|
|
35
|
+
*/
|
|
36
|
+
export declare function writeAttributionExtension(): void;
|
|
29
37
|
/**
|
|
30
38
|
* 生成「精简 UI」扩展到 <agentDir>/extensions/u1s1-compact-ui.js:
|
|
31
39
|
* - 隐藏内置工具调用(read/bash/edit/write/grep/find/ls),出错才显示一行;ctrl+o 可展开
|
package/dist/agent-setup.js
CHANGED
|
@@ -162,6 +162,27 @@ export function writeWebToolsExtension(cfg, features) {
|
|
|
162
162
|
subagentBlock +
|
|
163
163
|
`}\n`);
|
|
164
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* 生成「OpenRouter 应用归因」扩展到 <agentDir>/extensions/u1s1-attribution.js。
|
|
167
|
+
* 用户自己配 OPENROUTER_API_KEY 直连时,pi 内置的归因头归到 pi.dev 名下(且受遥测
|
|
168
|
+
* 开关控制);这里用 before_provider_headers 钩子覆盖为 u1s1,让这部分流量也计入
|
|
169
|
+
* u1s1 的 OpenRouter 公开排行与数据分析(openrouter.ai/docs/app-attribution)。
|
|
170
|
+
* 只在请求目标确认为 OpenRouter 时才改头,其它供应商不加多余头。
|
|
171
|
+
*/
|
|
172
|
+
export function writeAttributionExtension() {
|
|
173
|
+
const dir = join(agentDir, "extensions");
|
|
174
|
+
mkdirSync(dir, { recursive: true });
|
|
175
|
+
writeFileSync(join(dir, "u1s1-attribution.js"), `// 由 u1s1 每次启动自动生成,请勿手改\n` +
|
|
176
|
+
`export default async function (pi) {\n` +
|
|
177
|
+
` pi.on("before_provider_headers", (event, ctx) => {\n` +
|
|
178
|
+
` const m = ctx.model;\n` +
|
|
179
|
+
` if (!m || !(m.provider === "openrouter" || String(m.baseUrl ?? "").includes("openrouter.ai"))) return;\n` +
|
|
180
|
+
` event.headers["HTTP-Referer"] = "https://u1s1.io";\n` +
|
|
181
|
+
` event.headers["X-OpenRouter-Title"] = "u1s1";\n` +
|
|
182
|
+
` event.headers["X-OpenRouter-Categories"] = "cli-agent";\n` +
|
|
183
|
+
` });\n` +
|
|
184
|
+
`}\n`);
|
|
185
|
+
}
|
|
165
186
|
/**
|
|
166
187
|
* 生成「精简 UI」扩展到 <agentDir>/extensions/u1s1-compact-ui.js:
|
|
167
188
|
* - 隐藏内置工具调用(read/bash/edit/write/grep/find/ls),出错才显示一行;ctrl+o 可展开
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { execSync, spawnSync } from "node:child_process";
|
|
3
3
|
import { writeFileSync } from "node:fs";
|
|
4
|
-
import { cleanupBrandThemes, endpointKeyEnv, endpointProviderEntry, ensureBrandPrompt, ensureDefaultSettings, ensureProviderModels, ensureWorkflowPromptTemplate, scrubForeignProviderEnv, toProviderModels, writeCompactUiExtension, writeWebToolsExtension, } from "./agent-setup.js";
|
|
4
|
+
import { cleanupBrandThemes, endpointKeyEnv, endpointProviderEntry, ensureBrandPrompt, ensureDefaultSettings, ensureProviderModels, ensureWorkflowPromptTemplate, scrubForeignProviderEnv, toProviderModels, writeAttributionExtension, writeCompactUiExtension, writeWebToolsExtension, } from "./agent-setup.js";
|
|
5
5
|
import { printConsoleBanner } from "./brand.js";
|
|
6
6
|
import { agentDir, apiModelToDef, CUSTOM_ENDPOINTS, isPortableInstall, loadConfig, MODELS, persistPreferredModel, PROVIDER_ID, readSettings, refValid, resolvePreferredModel, setModelsFromApi, VERSION, } from "./config.js";
|
|
7
7
|
import { registerLoopCommand } from "./loop.js";
|
|
@@ -175,6 +175,8 @@ async function runAgent(cfg, args) {
|
|
|
175
175
|
});
|
|
176
176
|
// 精简 UI:隐藏工具调用 + 汇总行 + 隐藏思考标签(同样投影到 agentDir/extensions)
|
|
177
177
|
writeCompactUiExtension();
|
|
178
|
+
// OpenRouter 应用归因:直连流量计入 u1s1 的公开排行
|
|
179
|
+
writeAttributionExtension();
|
|
178
180
|
ensureTmuxKeyboardProtocol();
|
|
179
181
|
// must be set before pi reads them (getAgentDir() reads at call time, env at import is fine too)
|
|
180
182
|
process.env["PI_CODING_AGENT_DIR"] = agentDir;
|
package/dist/usage.js
CHANGED
|
@@ -46,11 +46,28 @@ export async function usage() {
|
|
|
46
46
|
};
|
|
47
47
|
if (me.packages.length === 0)
|
|
48
48
|
console.log(" 用量包 (无生效中的用量包)");
|
|
49
|
+
// 同种类、同范围、同有效期的包合并成一条展示(比如邀请多个好友拿到的多份邀请赠送)
|
|
50
|
+
const groups = new Map();
|
|
49
51
|
for (const p of me.packages) {
|
|
52
|
+
const key = `${p.kind}|${p.scope}|${p.daily_tokens != null}|${p.expires_at || ""}`;
|
|
53
|
+
const g = groups.get(key);
|
|
54
|
+
// 可空字段求和:两边都是 null 就保持 null,别把「一次性包没有日额度」污染成 0
|
|
55
|
+
const sumOpt = (a, b) => (a == null && b == null ? null : (a ?? 0) + (b ?? 0));
|
|
56
|
+
if (g) {
|
|
57
|
+
g.count += 1;
|
|
58
|
+
g.daily_tokens = sumOpt(g.daily_tokens, p.daily_tokens);
|
|
59
|
+
g.total_tokens = sumOpt(g.total_tokens, p.total_tokens);
|
|
60
|
+
g.remaining += p.remaining;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
groups.set(key, { ...p, count: 1 });
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
for (const p of groups.values()) {
|
|
50
67
|
const daily = p.daily_tokens != null;
|
|
51
68
|
const total = daily ? (p.daily_tokens ?? 0) : (p.total_tokens ?? 0);
|
|
52
69
|
const ratio = total > 0 ? p.remaining / total : 0;
|
|
53
|
-
const label = (PKG_LABEL[p.kind] ?? p.kind).padEnd(5, " ");
|
|
70
|
+
const label = ((PKG_LABEL[p.kind] ?? p.kind) + (p.count > 1 ? ` ×${p.count}` : "")).padEnd(5, " ");
|
|
54
71
|
const per = daily ? "/天" : "";
|
|
55
72
|
console.log(` ${label} 还剩 ${fmtTokensCn(p.remaining)} / ${fmtTokensCn(total)}${per} ${bar(ratio)}`);
|
|
56
73
|
const scopeNote = p.scope === "free" ? "仅默认模型和搜索 · 0 点恢复" : "全模型可用";
|
package/dist/web.js
CHANGED
|
@@ -2,7 +2,7 @@ import { spawn, spawnSync } from "node:child_process";
|
|
|
2
2
|
import { mkdirSync } from "node:fs";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { dirname, join } from "node:path";
|
|
5
|
-
import { cleanupBrandThemes, endpointKeyEnv, ensureAuthCredential, ensureBrandPrompt, ensureWorkflowPromptTemplate, ensureDefaultSettings, ensureProviderModels, scrubForeignProviderEnv, writeWebToolsExtension, } from "./agent-setup.js";
|
|
5
|
+
import { cleanupBrandThemes, endpointKeyEnv, ensureAuthCredential, ensureBrandPrompt, ensureWorkflowPromptTemplate, ensureDefaultSettings, ensureProviderModels, scrubForeignProviderEnv, writeAttributionExtension, writeWebToolsExtension, } from "./agent-setup.js";
|
|
6
6
|
import { agentDir, apiModelToDef, resolvePreferredModel, setModelsFromApi, u1s1Dir, writeAgentDefaultModel, } from "./config.js";
|
|
7
7
|
import { ensureSearchTools } from "./search-tools.js";
|
|
8
8
|
import { ensureUsableShell } from "./shell-doctor.js";
|
|
@@ -58,6 +58,8 @@ export async function prepareWebEnv(cfg) {
|
|
|
58
58
|
webFetchRender: webFetchRenderEnabled,
|
|
59
59
|
imageGen: imageGenEnabled,
|
|
60
60
|
});
|
|
61
|
+
// OpenRouter 应用归因:直连流量计入 u1s1 的公开排行(与 TUI 同源)
|
|
62
|
+
writeAttributionExtension();
|
|
61
63
|
// 网页版新会话从 settings.json 的 defaultModel 取模型(TUI 是每次传 --model),
|
|
62
64
|
// 确保它有值;resolvePreferredModel 优先尊重已有的 in-session 选择,不会回退覆盖。
|
|
63
65
|
const pref = resolvePreferredModel(cfg);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "u1s1-cli",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.4",
|
|
4
4
|
"description": "u1s1 — 有一说一,最省心的 AI 编程搭子。终端里用中文说需求,AI 帮你读文件、改代码、跑命令。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
"license": "MIT",
|
|
44
44
|
"homepage": "https://u1s1.io",
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@earendil-works/pi-coding-agent": "0.84.
|
|
47
|
-
"@earendil-works/pi-tui": "0.84.
|
|
46
|
+
"@earendil-works/pi-coding-agent": "0.84.3",
|
|
47
|
+
"@earendil-works/pi-tui": "0.84.3",
|
|
48
48
|
"typebox": "1.3.7"
|
|
49
49
|
},
|
|
50
50
|
"optionalDependencies": {
|