u1s1-cli 0.9.1 → 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/dist/agent-setup.js +25 -1
- package/dist/api.js +10 -5
- package/dist/config.js +3 -0
- package/dist/index.js +10 -11
- package/dist/tools.js +107 -66
- package/dist/web.js +9 -3
- package/package.json +1 -1
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,9 +18,9 @@ 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 ?? {} };
|
|
17
22
|
}
|
|
18
|
-
/** 联网搜索走网关代理(上游 key 只在服务端)。 */
|
|
23
|
+
/** 联网搜索走网关代理(上游 key 只在服务端)。maxResults 不传时由服务端决定默认值。 */
|
|
19
24
|
export async function searchWeb(cfg, query, maxResults, signal) {
|
|
20
25
|
if (!cfg.apiKey)
|
|
21
26
|
throw new Error("没有配置 API Key");
|
|
@@ -24,7 +29,7 @@ export async function searchWeb(cfg, query, maxResults, signal) {
|
|
|
24
29
|
resp = await fetch(`${cfg.baseUrl}/search`, {
|
|
25
30
|
method: "POST",
|
|
26
31
|
headers: {
|
|
27
|
-
|
|
32
|
+
...authHeaders(cfg.apiKey),
|
|
28
33
|
"content-type": "application/json",
|
|
29
34
|
},
|
|
30
35
|
body: JSON.stringify({ query, max_results: maxResults }),
|
|
@@ -48,7 +53,7 @@ export async function fetchMe(cfg) {
|
|
|
48
53
|
let resp;
|
|
49
54
|
try {
|
|
50
55
|
resp = await fetch(`${cfg.baseUrl}/me`, {
|
|
51
|
-
headers:
|
|
56
|
+
headers: authHeaders(cfg.apiKey),
|
|
52
57
|
});
|
|
53
58
|
}
|
|
54
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. */
|
package/dist/index.js
CHANGED
|
@@ -1,15 +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
|
-
import { createFetchTool, createSearchTool } from "./tools.js";
|
|
10
8
|
import { fetchModels } from "./api.js";
|
|
11
|
-
const require = createRequire(import.meta.url);
|
|
12
|
-
const VERSION = require("../package.json").version;
|
|
13
9
|
const PACKAGE_NAME = "u1s1-cli";
|
|
14
10
|
/**
|
|
15
11
|
* 启动时自动检查 npm 最新版,发现更新就静默安装。
|
|
@@ -114,18 +110,24 @@ async function runAgent(cfg, args) {
|
|
|
114
110
|
ensureBrandPrompt();
|
|
115
111
|
ensureDefaultSettings();
|
|
116
112
|
// Fetch model list from server; fall back to built-in MODELS on error.
|
|
113
|
+
// 服务端没开搜索(或老网关没有 features 字段)时不注册 web_search,模型就不会白调
|
|
114
|
+
let webSearchEnabled = true;
|
|
117
115
|
try {
|
|
118
|
-
const
|
|
119
|
-
setModelsFromApi(
|
|
116
|
+
const { models, features } = await fetchModels(cfg);
|
|
117
|
+
setModelsFromApi(models.map(apiModelToDef));
|
|
118
|
+
webSearchEnabled = features.web_search !== false;
|
|
120
119
|
}
|
|
121
120
|
catch (e) {
|
|
122
121
|
console.error(" 获取模型列表失败,使用内置列表:", e.message);
|
|
123
122
|
}
|
|
124
123
|
ensureProviderModels(cfg);
|
|
124
|
+
// 联网工具经 agentDir/extensions 投影,TUI 和 u1s1 web 共用一份注册
|
|
125
|
+
writeWebToolsExtension(cfg, webSearchEnabled);
|
|
125
126
|
ensureTmuxKeyboardProtocol();
|
|
126
127
|
// must be set before pi reads them (getAgentDir() reads at call time, env at import is fine too)
|
|
127
128
|
process.env["PI_CODING_AGENT_DIR"] = agentDir;
|
|
128
129
|
process.env["U1S1_API_KEY"] = cfg.apiKey;
|
|
130
|
+
process.env["U1S1_TOOLS_VIA_EXTENSION"] = "1";
|
|
129
131
|
// hide pi's own "Run pi update" banner; users should run `u1s1 update` instead
|
|
130
132
|
process.env["PI_SKIP_VERSION_CHECK"] = "1";
|
|
131
133
|
const { CustomEditor, main } = await import("@earendil-works/pi-coding-agent");
|
|
@@ -158,9 +160,6 @@ async function runAgent(cfg, args) {
|
|
|
158
160
|
name: "u1s1",
|
|
159
161
|
factory: (pi) => {
|
|
160
162
|
applyBrandUi(pi, VERSION);
|
|
161
|
-
// 联网能力:搜索走网关(上游 key 只在服务端),抓网页在本地直接出网
|
|
162
|
-
pi.registerTool(createSearchTool(cfg));
|
|
163
|
-
pi.registerTool(createFetchTool());
|
|
164
163
|
// pi 内置只有 /quit;补一个更常见的 /exit,方便新手退出
|
|
165
164
|
pi.registerCommand("exit", {
|
|
166
165
|
description: "退出 u1s1",
|
package/dist/tools.js
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
|
+
import { defineTool } from "@earendil-works/pi-coding-agent";
|
|
1
2
|
import { Type } from "typebox";
|
|
2
3
|
import { searchWeb } from "./api.js";
|
|
3
4
|
const FETCH_TIMEOUT_MS = 20_000;
|
|
4
5
|
const MAX_FETCH_BYTES = 2_000_000;
|
|
5
6
|
const MAX_TEXT_CHARS = 30_000;
|
|
7
|
+
const HTML_ENTITIES = {
|
|
8
|
+
" ": " ",
|
|
9
|
+
"&": "&",
|
|
10
|
+
"<": "<",
|
|
11
|
+
">": ">",
|
|
12
|
+
""": '"',
|
|
13
|
+
"'": "'",
|
|
14
|
+
};
|
|
6
15
|
/** 把网页 HTML 榨成纯文本:去掉脚本样式和标签,压掉多余空白。 */
|
|
7
16
|
function htmlToText(html) {
|
|
8
17
|
return html
|
|
@@ -11,12 +20,7 @@ function htmlToText(html) {
|
|
|
11
20
|
.replace(/<br\s*\/?>/gi, "\n")
|
|
12
21
|
.replace(/<\/(p|div|li|tr|h[1-6])>/gi, "\n")
|
|
13
22
|
.replace(/<[^>]+>/g, " ")
|
|
14
|
-
.replace(/ /g,
|
|
15
|
-
.replace(/&/g, "&")
|
|
16
|
-
.replace(/</g, "<")
|
|
17
|
-
.replace(/>/g, ">")
|
|
18
|
-
.replace(/"/g, '"')
|
|
19
|
-
.replace(/'/g, "'")
|
|
23
|
+
.replace(/&(?:nbsp|amp|lt|gt|quot|#39);/g, (m) => HTML_ENTITIES[m] ?? m)
|
|
20
24
|
.replace(/[ \t]+/g, " ")
|
|
21
25
|
.replace(/\n\s*\n\s*\n+/g, "\n\n")
|
|
22
26
|
.trim();
|
|
@@ -26,9 +30,48 @@ function truncate(text) {
|
|
|
26
30
|
return text;
|
|
27
31
|
return `${text.slice(0, MAX_TEXT_CHARS)}\n\n…(内容过长已截断,共 ${text.length} 字符)`;
|
|
28
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
|
+
}
|
|
29
72
|
/** 联网搜索工具:走 u1s1 网关代理,上游 key 不落到用户机器上。 */
|
|
30
73
|
export function createSearchTool(cfg) {
|
|
31
|
-
return {
|
|
74
|
+
return defineTool({
|
|
32
75
|
name: "web_search",
|
|
33
76
|
label: "联网搜索",
|
|
34
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.",
|
|
@@ -42,7 +85,7 @@ export function createSearchTool(cfg) {
|
|
|
42
85
|
maxResults: Type.Optional(Type.Number({ description: "How many results to return (1-10, default 5).", minimum: 1, maximum: 10 })),
|
|
43
86
|
}),
|
|
44
87
|
async execute(_toolCallId, params, signal) {
|
|
45
|
-
const data = await searchWeb(cfg, params.query, params.maxResults
|
|
88
|
+
const data = await searchWeb(cfg, params.query, params.maxResults, signal);
|
|
46
89
|
const lines = [];
|
|
47
90
|
if (data.answer)
|
|
48
91
|
lines.push(`Answer: ${data.answer}`, "");
|
|
@@ -59,63 +102,61 @@ export function createSearchTool(cfg) {
|
|
|
59
102
|
details: { query: data.query, count: data.results.length },
|
|
60
103
|
};
|
|
61
104
|
},
|
|
62
|
-
};
|
|
105
|
+
});
|
|
63
106
|
}
|
|
64
107
|
/** 抓网页:纯客户端出网,不经过我们的服务器,也不额外计费。 */
|
|
65
|
-
export
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
};
|
|
121
|
-
}
|
|
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/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
|
});
|