u1s1-cli 0.8.0 → 0.9.2
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/README.md +4 -4
- package/dist/agent-setup.js +25 -1
- package/dist/api.js +35 -3
- package/dist/config.js +4 -1
- package/dist/index.js +10 -7
- package/dist/login.js +4 -4
- package/dist/tools.js +162 -0
- package/dist/usage.js +9 -7
- package/dist/web.js +9 -3
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# u1s1 — 有一说一,最省心的 AI 编程搭子
|
|
2
2
|
|
|
3
|
-
在终端里用中文说需求,AI 帮你读文件、改代码、跑命令。不用买模型、不用配 API
|
|
3
|
+
在终端里用中文说需求,AI 帮你读文件、改代码、跑命令。不用买模型、不用配 API、不用懂那些名词,默认 DeepSeek V4 Flash **每天免费 $2**(北京时间 0 点恢复),新用户另送一次性 $10 加量。
|
|
4
4
|
|
|
5
5
|
## 三步开始
|
|
6
6
|
|
|
@@ -48,9 +48,9 @@ u1s1
|
|
|
48
48
|
|
|
49
49
|
## 有一说一
|
|
50
50
|
|
|
51
|
-
- **背后模型**:默认 DeepSeek V4 Flash(1M
|
|
52
|
-
-
|
|
53
|
-
- **额度不够**:邀请朋友,你俩各得 $1
|
|
51
|
+
- **背后模型**:默认 DeepSeek V4 Flash(1M 上下文,每天免费 $2);难题可随时 `u1s1 model grok` 切 Grok 4.6。对话里 `/model` 也会记住,下次启动还是这个。
|
|
52
|
+
- **怎么收费**:DeepSeek V4 Flash 每天有 $2 免费用量,北京时间 0 点恢复且不累计。免费用完或切换其他模型后,按 API 实际成本从永久余额扣,不加价;新用户另送一次性 $10 加量。
|
|
53
|
+
- **额度不够**:邀请朋友,你俩各得 $1 永久加量 → [u1s1.io/dashboard](https://u1s1.io/dashboard)
|
|
54
54
|
- **内核**:基于开源的 [pi](https://pi.dev) coding agent,会话管理、斜杠命令、皮肤等能力全都有。
|
|
55
55
|
|
|
56
56
|
官网:[u1s1.io](https://u1s1.io)
|
package/dist/agent-setup.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import { agentDir, MODELS, PROVIDER_ID } from "./config.js";
|
|
3
|
+
import { agentDir, MODELS, PROVIDER_ID, VERSION } from "./config.js";
|
|
4
4
|
const BRAND_APPEND = `## u1s1
|
|
5
5
|
|
|
6
6
|
你是 u1s1(有一说一) —— 说人话的 AI 编程搭子,一个面向编程新手的中文 AI 编程助手。用户很可能不熟悉编程术语:
|
|
@@ -84,6 +84,28 @@ export function cleanupBrandThemes() {
|
|
|
84
84
|
* itself holds no secret. Rewritten on every launch so baseUrl/model changes
|
|
85
85
|
* propagate; other providers a user may have added are preserved.
|
|
86
86
|
*/
|
|
87
|
+
/**
|
|
88
|
+
* 联网工具经 <agentDir>/extensions 投影:pi 的资源加载器对 TUI 和 `u1s1 web`
|
|
89
|
+
* 都会扫描这个目录,两个前端从此共用同一份工具注册,不用各接一遍。
|
|
90
|
+
* 文件每次启动重写(baseUrl/服务端开关变化随之生效);apiKey 走 U1S1_API_KEY
|
|
91
|
+
* 环境变量,文件里不落密钥。U1S1_TOOLS_VIA_EXTENSION 守卫:旧版 CLI 仍在
|
|
92
|
+
* 进程内注册工具且不设该变量,残留的本文件在旧版下自动空转,避免双重注册。
|
|
93
|
+
*/
|
|
94
|
+
export function writeWebToolsExtension(cfg, webSearchEnabled) {
|
|
95
|
+
const dir = join(agentDir, "extensions");
|
|
96
|
+
mkdirSync(dir, { recursive: true });
|
|
97
|
+
const toolsUrl = new URL("./tools.js", import.meta.url).href;
|
|
98
|
+
const searchLine = webSearchEnabled
|
|
99
|
+
? ` pi.registerTool(tools.createSearchTool({ baseUrl: ${JSON.stringify(cfg.baseUrl)}, apiKey: process.env.U1S1_API_KEY }));\n`
|
|
100
|
+
: "";
|
|
101
|
+
writeFileSync(join(dir, "u1s1-tools.js"), `// 由 u1s1 每次启动自动生成,请勿手改\n` +
|
|
102
|
+
`export default async function (pi) {\n` +
|
|
103
|
+
` if (process.env.U1S1_TOOLS_VIA_EXTENSION !== "1") return;\n` +
|
|
104
|
+
` const tools = await import(${JSON.stringify(toolsUrl)});\n` +
|
|
105
|
+
searchLine +
|
|
106
|
+
` pi.registerTool(tools.webFetchTool);\n` +
|
|
107
|
+
`}\n`);
|
|
108
|
+
}
|
|
87
109
|
export function ensureProviderModels(cfg) {
|
|
88
110
|
mkdirSync(agentDir, { recursive: true });
|
|
89
111
|
const p = join(agentDir, "models.json");
|
|
@@ -104,6 +126,8 @@ export function ensureProviderModels(cfg) {
|
|
|
104
126
|
baseUrl: cfg.baseUrl,
|
|
105
127
|
api: "openai-completions",
|
|
106
128
|
apiKey: "$U1S1_API_KEY",
|
|
129
|
+
// 网关按这个头识别客户端版本;不带头的旧版会在会话首轮被追加升级提示
|
|
130
|
+
headers: { "x-u1s1-version": VERSION },
|
|
107
131
|
models: MODELS.map((m) => ({
|
|
108
132
|
id: m.id,
|
|
109
133
|
name: m.name,
|
package/dist/api.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
import { VERSION } from "./config.js";
|
|
2
|
+
/** 网关按 x-u1s1-version 识别客户端版本(旧版 CLI 不带,提示升级)。 */
|
|
3
|
+
function authHeaders(apiKey) {
|
|
4
|
+
return { authorization: `Bearer ${apiKey}`, "x-u1s1-version": VERSION };
|
|
5
|
+
}
|
|
1
6
|
export async function fetchModels(cfg) {
|
|
2
7
|
let resp;
|
|
3
8
|
try {
|
|
4
9
|
resp = await fetch(`${cfg.baseUrl}/models`, {
|
|
5
|
-
headers:
|
|
10
|
+
headers: authHeaders(cfg.apiKey),
|
|
6
11
|
});
|
|
7
12
|
}
|
|
8
13
|
catch {
|
|
@@ -13,7 +18,34 @@ export async function fetchModels(cfg) {
|
|
|
13
18
|
if (!resp.ok)
|
|
14
19
|
throw new Error(`服务端返回 ${resp.status},稍后再试`);
|
|
15
20
|
const body = (await resp.json());
|
|
16
|
-
return body.data;
|
|
21
|
+
return { models: body.data, features: body.features ?? {} };
|
|
22
|
+
}
|
|
23
|
+
/** 联网搜索走网关代理(上游 key 只在服务端)。maxResults 不传时由服务端决定默认值。 */
|
|
24
|
+
export async function searchWeb(cfg, query, maxResults, signal) {
|
|
25
|
+
if (!cfg.apiKey)
|
|
26
|
+
throw new Error("没有配置 API Key");
|
|
27
|
+
let resp;
|
|
28
|
+
try {
|
|
29
|
+
resp = await fetch(`${cfg.baseUrl}/search`, {
|
|
30
|
+
method: "POST",
|
|
31
|
+
headers: {
|
|
32
|
+
...authHeaders(cfg.apiKey),
|
|
33
|
+
"content-type": "application/json",
|
|
34
|
+
},
|
|
35
|
+
body: JSON.stringify({ query, max_results: maxResults }),
|
|
36
|
+
signal,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
throw new Error(`连不上 ${cfg.baseUrl},检查一下网络?`);
|
|
41
|
+
}
|
|
42
|
+
if (resp.status === 401)
|
|
43
|
+
throw new Error("这把 Key 不对或已失效,去 https://u1s1.io/dashboard 看看");
|
|
44
|
+
if (!resp.ok) {
|
|
45
|
+
const body = (await resp.json().catch(() => null));
|
|
46
|
+
throw new Error(body?.error?.message ?? `搜索服务返回 ${resp.status},稍后再试`);
|
|
47
|
+
}
|
|
48
|
+
return (await resp.json());
|
|
17
49
|
}
|
|
18
50
|
export async function fetchMe(cfg) {
|
|
19
51
|
if (!cfg.apiKey)
|
|
@@ -21,7 +53,7 @@ export async function fetchMe(cfg) {
|
|
|
21
53
|
let resp;
|
|
22
54
|
try {
|
|
23
55
|
resp = await fetch(`${cfg.baseUrl}/me`, {
|
|
24
|
-
headers:
|
|
56
|
+
headers: authHeaders(cfg.apiKey),
|
|
25
57
|
});
|
|
26
58
|
}
|
|
27
59
|
catch {
|
package/dist/config.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
2
3
|
import { homedir } from "node:os";
|
|
3
4
|
import { join } from "node:path";
|
|
5
|
+
const require = createRequire(import.meta.url);
|
|
6
|
+
export const VERSION = require("../package.json").version;
|
|
4
7
|
export const DEFAULT_BASE_URL = "https://api.u1s1.io/v1";
|
|
5
8
|
export const PROVIDER_ID = "u1s1";
|
|
6
9
|
/** Make a short alias from a model id by stripping common prefixes. */
|
|
@@ -40,7 +43,7 @@ export const MODELS = [
|
|
|
40
43
|
contextWindow: 1_048_576,
|
|
41
44
|
maxTokens: 384_000,
|
|
42
45
|
cost: { input: 0.14, output: 0.28, cacheRead: 0, cacheWrite: 0 },
|
|
43
|
-
note: "默认 ·
|
|
46
|
+
note: "默认 · 每日 $2 免费,日常写代码首选",
|
|
44
47
|
},
|
|
45
48
|
{
|
|
46
49
|
id: "x-ai/grok-4.6",
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { spawnSync } from "node:child_process";
|
|
3
3
|
import { writeFileSync } from "node:fs";
|
|
4
|
-
import {
|
|
5
|
-
import { cleanupBrandThemes, ensureBrandPrompt, ensureDefaultSettings, ensureProviderModels, } from "./agent-setup.js";
|
|
4
|
+
import { cleanupBrandThemes, ensureBrandPrompt, ensureDefaultSettings, ensureProviderModels, writeWebToolsExtension, } from "./agent-setup.js";
|
|
6
5
|
import { printConsoleBanner } from "./brand.js";
|
|
7
|
-
import { agentDir, apiModelToDef, loadConfig, MODELS, persistPreferredModel, PROVIDER_ID, readSettings, resolvePreferredModel, setModelsFromApi, } from "./config.js";
|
|
6
|
+
import { agentDir, apiModelToDef, loadConfig, MODELS, persistPreferredModel, PROVIDER_ID, readSettings, resolvePreferredModel, setModelsFromApi, VERSION, } from "./config.js";
|
|
8
7
|
import { applyBrandUi } from "./style.js";
|
|
9
8
|
import { fetchModels } from "./api.js";
|
|
10
|
-
const require = createRequire(import.meta.url);
|
|
11
|
-
const VERSION = require("../package.json").version;
|
|
12
9
|
const PACKAGE_NAME = "u1s1-cli";
|
|
13
10
|
/**
|
|
14
11
|
* 启动时自动检查 npm 最新版,发现更新就静默安装。
|
|
@@ -113,18 +110,24 @@ async function runAgent(cfg, args) {
|
|
|
113
110
|
ensureBrandPrompt();
|
|
114
111
|
ensureDefaultSettings();
|
|
115
112
|
// Fetch model list from server; fall back to built-in MODELS on error.
|
|
113
|
+
// 服务端没开搜索(或老网关没有 features 字段)时不注册 web_search,模型就不会白调
|
|
114
|
+
let webSearchEnabled = true;
|
|
116
115
|
try {
|
|
117
|
-
const
|
|
118
|
-
setModelsFromApi(
|
|
116
|
+
const { models, features } = await fetchModels(cfg);
|
|
117
|
+
setModelsFromApi(models.map(apiModelToDef));
|
|
118
|
+
webSearchEnabled = features.web_search !== false;
|
|
119
119
|
}
|
|
120
120
|
catch (e) {
|
|
121
121
|
console.error(" 获取模型列表失败,使用内置列表:", e.message);
|
|
122
122
|
}
|
|
123
123
|
ensureProviderModels(cfg);
|
|
124
|
+
// 联网工具经 agentDir/extensions 投影,TUI 和 u1s1 web 共用一份注册
|
|
125
|
+
writeWebToolsExtension(cfg, webSearchEnabled);
|
|
124
126
|
ensureTmuxKeyboardProtocol();
|
|
125
127
|
// must be set before pi reads them (getAgentDir() reads at call time, env at import is fine too)
|
|
126
128
|
process.env["PI_CODING_AGENT_DIR"] = agentDir;
|
|
127
129
|
process.env["U1S1_API_KEY"] = cfg.apiKey;
|
|
130
|
+
process.env["U1S1_TOOLS_VIA_EXTENSION"] = "1";
|
|
128
131
|
// hide pi's own "Run pi update" banner; users should run `u1s1 update` instead
|
|
129
132
|
process.env["PI_SKIP_VERSION_CHECK"] = "1";
|
|
130
133
|
const { CustomEditor, main } = await import("@earendil-works/pi-coding-agent");
|
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 秒,DeepSeek 每天免费 $2)`);
|
|
78
78
|
console.log(" 2. 复制你的 API Key,粘贴到下面");
|
|
79
79
|
console.log("");
|
|
80
80
|
tryOpenBrowser(DASHBOARD_URL);
|
|
@@ -91,12 +91,12 @@ 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(" 用浏览器登录(DeepSeek 每天免费 $2):");
|
|
95
95
|
console.log("");
|
|
96
96
|
console.log(` ${start.verify_url}`);
|
|
97
97
|
console.log("");
|
|
98
98
|
console.log(" 已经帮你打开浏览器了;如果没打开,把上面这行网址复制到浏览器打开。");
|
|
99
|
-
console.log("
|
|
99
|
+
console.log(" 在浏览器里登录并点「批准」后,这里会自动继续,等着就行……");
|
|
100
100
|
tryOpenBrowser(start.verify_url);
|
|
101
101
|
key = (await pollDeviceLogin(origin, start)) ?? undefined;
|
|
102
102
|
if (!key) {
|
|
@@ -119,7 +119,7 @@ export async function login(keyArg) {
|
|
|
119
119
|
process.exit(1);
|
|
120
120
|
});
|
|
121
121
|
saveConfig(next);
|
|
122
|
-
console.log(` ✓ 登录成功${me.email ? `(${me.email})` : ""}
|
|
122
|
+
console.log(` ✓ 登录成功${me.email ? `(${me.email})` : ""},今日免费还剩 $${me.daily_free_remaining_usd},永久余额 $${me.remaining_usd}。`);
|
|
123
123
|
return next;
|
|
124
124
|
}
|
|
125
125
|
/** Returns a config that definitely has an apiKey, prompting the user if needed. */
|
package/dist/tools.js
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { defineTool } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { Type } from "typebox";
|
|
3
|
+
import { searchWeb } from "./api.js";
|
|
4
|
+
const FETCH_TIMEOUT_MS = 20_000;
|
|
5
|
+
const MAX_FETCH_BYTES = 2_000_000;
|
|
6
|
+
const MAX_TEXT_CHARS = 30_000;
|
|
7
|
+
const HTML_ENTITIES = {
|
|
8
|
+
" ": " ",
|
|
9
|
+
"&": "&",
|
|
10
|
+
"<": "<",
|
|
11
|
+
">": ">",
|
|
12
|
+
""": '"',
|
|
13
|
+
"'": "'",
|
|
14
|
+
};
|
|
15
|
+
/** 把网页 HTML 榨成纯文本:去掉脚本样式和标签,压掉多余空白。 */
|
|
16
|
+
function htmlToText(html) {
|
|
17
|
+
return html
|
|
18
|
+
.replace(/<!--[\s\S]*?-->/g, "")
|
|
19
|
+
.replace(/<(script|style|noscript|svg|iframe)\b[\s\S]*?<\/\1>/gi, "")
|
|
20
|
+
.replace(/<br\s*\/?>/gi, "\n")
|
|
21
|
+
.replace(/<\/(p|div|li|tr|h[1-6])>/gi, "\n")
|
|
22
|
+
.replace(/<[^>]+>/g, " ")
|
|
23
|
+
.replace(/&(?:nbsp|amp|lt|gt|quot|#39);/g, (m) => HTML_ENTITIES[m] ?? m)
|
|
24
|
+
.replace(/[ \t]+/g, " ")
|
|
25
|
+
.replace(/\n\s*\n\s*\n+/g, "\n\n")
|
|
26
|
+
.trim();
|
|
27
|
+
}
|
|
28
|
+
function truncate(text) {
|
|
29
|
+
if (text.length <= MAX_TEXT_CHARS)
|
|
30
|
+
return text;
|
|
31
|
+
return `${text.slice(0, MAX_TEXT_CHARS)}\n\n…(内容过长已截断,共 ${text.length} 字符)`;
|
|
32
|
+
}
|
|
33
|
+
/** 只下载前 maxBytes 就断流,超大页面不用整个拉完再丢。 */
|
|
34
|
+
async function readBodyCapped(resp, maxBytes) {
|
|
35
|
+
if (!resp.body)
|
|
36
|
+
return new Uint8Array(await resp.arrayBuffer()).subarray(0, maxBytes);
|
|
37
|
+
const reader = resp.body.getReader();
|
|
38
|
+
const chunks = [];
|
|
39
|
+
let total = 0;
|
|
40
|
+
for (;;) {
|
|
41
|
+
const { done, value } = await reader.read();
|
|
42
|
+
if (done)
|
|
43
|
+
break;
|
|
44
|
+
chunks.push(value);
|
|
45
|
+
total += value.byteLength;
|
|
46
|
+
if (total >= maxBytes) {
|
|
47
|
+
void reader.cancel().catch(() => { });
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const out = new Uint8Array(Math.min(total, maxBytes));
|
|
52
|
+
let offset = 0;
|
|
53
|
+
for (const chunk of chunks) {
|
|
54
|
+
const room = out.byteLength - offset;
|
|
55
|
+
if (room <= 0)
|
|
56
|
+
break;
|
|
57
|
+
out.set(room < chunk.byteLength ? chunk.subarray(0, room) : chunk, offset);
|
|
58
|
+
offset += chunk.byteLength;
|
|
59
|
+
}
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
62
|
+
/** 按响应头声明的 charset 解码(GBK 等中文页面不至于乱码),没有或不认识就按 UTF-8。 */
|
|
63
|
+
function decodeBody(bytes, contentType) {
|
|
64
|
+
const charset = /charset=["']?([\w-]+)/i.exec(contentType)?.[1];
|
|
65
|
+
try {
|
|
66
|
+
return new TextDecoder(charset || "utf-8").decode(bytes);
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return new TextDecoder("utf-8").decode(bytes);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/** 联网搜索工具:走 u1s1 网关代理,上游 key 不落到用户机器上。 */
|
|
73
|
+
export function createSearchTool(cfg) {
|
|
74
|
+
return defineTool({
|
|
75
|
+
name: "web_search",
|
|
76
|
+
label: "联网搜索",
|
|
77
|
+
description: "Search the web for current information. Use it for anything time-sensitive or outside the codebase: library docs, error messages, latest versions, recent events. Returns a short answer plus ranked results with URLs and snippets. Follow up with web_fetch to read a promising result in full.",
|
|
78
|
+
promptSnippet: "搜索互联网获取最新信息(文档、报错、版本、时事)",
|
|
79
|
+
promptGuidelines: [
|
|
80
|
+
"Use web_search when the answer depends on information newer than your knowledge or not present in the repository, instead of guessing.",
|
|
81
|
+
"Prefer one focused web_search query over several near-duplicate queries; each search costs the user credits.",
|
|
82
|
+
],
|
|
83
|
+
parameters: Type.Object({
|
|
84
|
+
query: Type.String({ description: "Search query. Be specific; keep it under ~15 words." }),
|
|
85
|
+
maxResults: Type.Optional(Type.Number({ description: "How many results to return (1-10, default 5).", minimum: 1, maximum: 10 })),
|
|
86
|
+
}),
|
|
87
|
+
async execute(_toolCallId, params, signal) {
|
|
88
|
+
const data = await searchWeb(cfg, params.query, params.maxResults, signal);
|
|
89
|
+
const lines = [];
|
|
90
|
+
if (data.answer)
|
|
91
|
+
lines.push(`Answer: ${data.answer}`, "");
|
|
92
|
+
if (data.results.length === 0) {
|
|
93
|
+
lines.push("No results.");
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
data.results.forEach((r, i) => {
|
|
97
|
+
lines.push(`${i + 1}. ${r.title}`, ` ${r.url}`, ` ${r.snippet}`, "");
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
content: [{ type: "text", text: truncate(lines.join("\n").trim()) }],
|
|
102
|
+
details: { query: data.query, count: data.results.length },
|
|
103
|
+
};
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
/** 抓网页:纯客户端出网,不经过我们的服务器,也不额外计费。 */
|
|
108
|
+
export const webFetchTool = defineTool({
|
|
109
|
+
name: "web_fetch",
|
|
110
|
+
label: "读取网页",
|
|
111
|
+
description: "Fetch a URL and return its readable text content (HTML is stripped to text; JSON and plain text are returned as-is). Use it to read a page found via web_search, or any URL the user pasted.",
|
|
112
|
+
promptSnippet: "抓取指定网址并转成可读文本",
|
|
113
|
+
promptGuidelines: [
|
|
114
|
+
"Use web_fetch to read a specific URL, and web_search when you still need to find the URL.",
|
|
115
|
+
],
|
|
116
|
+
parameters: Type.Object({
|
|
117
|
+
url: Type.String({ description: "Absolute http(s) URL to fetch." }),
|
|
118
|
+
}),
|
|
119
|
+
async execute(_toolCallId, params, signal) {
|
|
120
|
+
let url;
|
|
121
|
+
try {
|
|
122
|
+
// 用户从聊天工具粘来的链接常带 "@https://…" 前缀,顺手剥掉
|
|
123
|
+
url = new URL(params.url.trim().replace(/^@/, ""));
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
throw new Error(`不是合法的网址: ${params.url}`);
|
|
127
|
+
}
|
|
128
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
129
|
+
throw new Error(`只支持 http/https,收到 ${url.protocol}`);
|
|
130
|
+
}
|
|
131
|
+
const timeout = AbortSignal.timeout(FETCH_TIMEOUT_MS);
|
|
132
|
+
const abort = signal ? AbortSignal.any([signal, timeout]) : timeout;
|
|
133
|
+
let resp;
|
|
134
|
+
try {
|
|
135
|
+
resp = await fetch(url, {
|
|
136
|
+
redirect: "follow",
|
|
137
|
+
headers: {
|
|
138
|
+
accept: "text/html,application/xhtml+xml,application/json,text/plain;q=0.9,*/*;q=0.8",
|
|
139
|
+
"user-agent": "u1s1-cli",
|
|
140
|
+
},
|
|
141
|
+
signal: abort,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
catch (e) {
|
|
145
|
+
throw new Error(`打不开 ${url.href}: ${e.message}`);
|
|
146
|
+
}
|
|
147
|
+
if (!resp.ok)
|
|
148
|
+
throw new Error(`${url.href} 返回 ${resp.status} ${resp.statusText}`);
|
|
149
|
+
const type = resp.headers.get("content-type") ?? "";
|
|
150
|
+
if (!/text\/|json|xml|javascript/i.test(type)) {
|
|
151
|
+
throw new Error(`${url.href} 不是文本内容 (${type || "unknown"}),读不了`);
|
|
152
|
+
}
|
|
153
|
+
const raw = decodeBody(await readBodyCapped(resp, MAX_FETCH_BYTES), type);
|
|
154
|
+
const text = /html|xml/i.test(type) ? htmlToText(raw) : raw.trim();
|
|
155
|
+
return {
|
|
156
|
+
content: [
|
|
157
|
+
{ type: "text", text: truncate(`# ${url.href}\n\n${text || "(空白页面)"}`) },
|
|
158
|
+
],
|
|
159
|
+
details: { url: url.href, contentType: type, chars: text.length },
|
|
160
|
+
};
|
|
161
|
+
},
|
|
162
|
+
});
|
package/dist/usage.js
CHANGED
|
@@ -15,14 +15,16 @@ export async function usage() {
|
|
|
15
15
|
process.exit(1);
|
|
16
16
|
});
|
|
17
17
|
const remain = me.remaining_usd;
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
18
|
+
const freeRemain = me.daily_free_remaining_usd;
|
|
19
|
+
const freeTotal = me.daily_free_usd;
|
|
20
|
+
const freeRatio = freeTotal > 0 ? freeRemain / freeTotal : 0;
|
|
21
21
|
console.log("");
|
|
22
|
-
console.log(` 账号
|
|
23
|
-
console.log(`
|
|
24
|
-
console.log(
|
|
22
|
+
console.log(` 账号 ${me.email ?? "(未绑定邮箱)"}`);
|
|
23
|
+
console.log(` 今日免费 $${freeRemain} / $${freeTotal} ${bar(freeRatio)}`);
|
|
24
|
+
console.log(" DeepSeek V4 Flash · 北京时间 0 点恢复");
|
|
25
|
+
console.log(` 永久余额 $${remain}`);
|
|
26
|
+
console.log(` 本月成本 $${me.mtd_usd}`);
|
|
25
27
|
console.log("");
|
|
26
|
-
console.log("
|
|
28
|
+
console.log(" 免费额度每天自动恢复;邀请朋友双方各得永久加量 → https://u1s1.io/dashboard");
|
|
27
29
|
console.log("");
|
|
28
30
|
}
|
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, ensureBrandPrompt, ensureDefaultSettings, ensureProviderModels, } from "./agent-setup.js";
|
|
5
|
+
import { cleanupBrandThemes, ensureBrandPrompt, ensureDefaultSettings, ensureProviderModels, writeWebToolsExtension, } from "./agent-setup.js";
|
|
6
6
|
import { agentDir, apiModelToDef, resolvePreferredModel, setModelsFromApi, u1s1Dir, writeAgentDefaultModel, } from "./config.js";
|
|
7
7
|
import { applyWebUiBranding } from "./webui-brand.js";
|
|
8
8
|
import { fetchModels } from "./api.js";
|
|
@@ -49,14 +49,19 @@ export async function webCommand(cfg, args) {
|
|
|
49
49
|
ensureBrandPrompt();
|
|
50
50
|
ensureDefaultSettings();
|
|
51
51
|
// Fetch model list from server; fall back to built-in MODELS on error.
|
|
52
|
+
// 服务端没开搜索(或老网关没有 features 字段)时不注册 web_search
|
|
53
|
+
let webSearchEnabled = true;
|
|
52
54
|
try {
|
|
53
|
-
const
|
|
54
|
-
setModelsFromApi(
|
|
55
|
+
const { models, features } = await fetchModels(cfg);
|
|
56
|
+
setModelsFromApi(models.map(apiModelToDef));
|
|
57
|
+
webSearchEnabled = features.web_search !== false;
|
|
55
58
|
}
|
|
56
59
|
catch (e) {
|
|
57
60
|
console.error(" 获取模型列表失败,使用内置列表:", e.message);
|
|
58
61
|
}
|
|
59
62
|
ensureProviderModels(cfg);
|
|
63
|
+
// 联网工具经 agentDir/extensions 投影,和 TUI 共用一份注册
|
|
64
|
+
writeWebToolsExtension(cfg, webSearchEnabled);
|
|
60
65
|
// 网页版新会话从 settings.json 的 defaultModel 取模型(TUI 是每次传 --model),
|
|
61
66
|
// 确保它有值;resolvePreferredModel 优先尊重已有的 in-session 选择,不会回退覆盖。
|
|
62
67
|
writeAgentDefaultModel(resolvePreferredModel(cfg.model));
|
|
@@ -70,6 +75,7 @@ export async function webCommand(cfg, args) {
|
|
|
70
75
|
...process.env,
|
|
71
76
|
PI_CODING_AGENT_DIR: agentDir,
|
|
72
77
|
U1S1_API_KEY: cfg.apiKey,
|
|
78
|
+
U1S1_TOOLS_VIA_EXTENSION: "1",
|
|
73
79
|
PI_WEB_DATA_DIR: dataDir,
|
|
74
80
|
},
|
|
75
81
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "u1s1-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.2",
|
|
4
4
|
"description": "u1s1 — 有一说一,最省心的 AI 编程搭子。终端里用中文说需求,AI 帮你读文件、改代码、跑命令。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -32,7 +32,8 @@
|
|
|
32
32
|
"homepage": "https://u1s1.io",
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@earendil-works/pi-coding-agent": "0.84.2",
|
|
35
|
-
"@earendil-works/pi-tui": "0.84.2"
|
|
35
|
+
"@earendil-works/pi-tui": "0.84.2",
|
|
36
|
+
"typebox": "1.3.7"
|
|
36
37
|
},
|
|
37
38
|
"optionalDependencies": {
|
|
38
39
|
"pi-web-ui": "0.20.1"
|