u1s1-cli 1.2.8 → 1.2.9
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/api.js +14 -15
- package/package.json +3 -3
- package/scripts/patch-pi.js +4 -4
package/dist/api.js
CHANGED
|
@@ -3,6 +3,11 @@ import { authorizedFetch } from "./device-auth.js";
|
|
|
3
3
|
/** 401:凭证失效(设备被移除/换过钥匙),调用方应引导重新登录而不是继续硬跑。 */
|
|
4
4
|
export class AuthError extends Error {
|
|
5
5
|
}
|
|
6
|
+
/** 网关错误壳统一是 { error: { message } };解析不出来时回退到状态码提示。 */
|
|
7
|
+
async function errorMessageFromResponse(resp, fallback) {
|
|
8
|
+
const body = (await resp.json().catch(() => null));
|
|
9
|
+
return body?.error?.message ?? fallback;
|
|
10
|
+
}
|
|
6
11
|
export async function fetchModels(cfg) {
|
|
7
12
|
let resp;
|
|
8
13
|
try {
|
|
@@ -17,7 +22,7 @@ export async function fetchModels(cfg) {
|
|
|
17
22
|
if (resp.status === 401)
|
|
18
23
|
throw new AuthError("登录已失效,请重新运行 u1s1 login");
|
|
19
24
|
if (!resp.ok)
|
|
20
|
-
throw new Error(`服务端返回 ${resp.status},稍后再试`);
|
|
25
|
+
throw new Error(await errorMessageFromResponse(resp, `服务端返回 ${resp.status},稍后再试`));
|
|
21
26
|
const body = (await resp.json());
|
|
22
27
|
return { models: body.data, features: body.features ?? {}, announcement: body.announcement };
|
|
23
28
|
}
|
|
@@ -37,7 +42,7 @@ export async function fetchUserEndpoints(cfg) {
|
|
|
37
42
|
throw new Error(`连不上 ${cfg.baseUrl}`);
|
|
38
43
|
}
|
|
39
44
|
if (!resp.ok)
|
|
40
|
-
throw new Error(`服务端返回 ${resp.status}`);
|
|
45
|
+
throw new Error(await errorMessageFromResponse(resp, `服务端返回 ${resp.status}`));
|
|
41
46
|
const body = (await resp.json());
|
|
42
47
|
return Array.isArray(body.endpoints) ? body.endpoints : [];
|
|
43
48
|
}
|
|
@@ -76,10 +81,8 @@ export async function searchWeb(cfg, input) {
|
|
|
76
81
|
}
|
|
77
82
|
if (resp.status === 401)
|
|
78
83
|
throw new Error("登录已失效,请重新运行 u1s1 login");
|
|
79
|
-
if (!resp.ok)
|
|
80
|
-
|
|
81
|
-
throw new Error(body?.error?.message ?? `搜索服务返回 ${resp.status},稍后再试`);
|
|
82
|
-
}
|
|
84
|
+
if (!resp.ok)
|
|
85
|
+
throw new Error(await errorMessageFromResponse(resp, `搜索服务返回 ${resp.status},稍后再试`));
|
|
83
86
|
return (await resp.json());
|
|
84
87
|
}
|
|
85
88
|
/** web_fetch 直连失败时的回退:网关用 Cloudflare Browser Rendering 渲染后转 markdown。 */
|
|
@@ -103,10 +106,8 @@ export async function renderPage(cfg, url, signal) {
|
|
|
103
106
|
}
|
|
104
107
|
if (resp.status === 401)
|
|
105
108
|
throw new Error("登录已失效,请重新运行 u1s1 login");
|
|
106
|
-
if (!resp.ok)
|
|
107
|
-
|
|
108
|
-
throw new Error(body?.error?.message ?? `渲染服务返回 ${resp.status}`);
|
|
109
|
-
}
|
|
109
|
+
if (!resp.ok)
|
|
110
|
+
throw new Error(await errorMessageFromResponse(resp, `渲染服务返回 ${resp.status}`));
|
|
110
111
|
return (await resp.json());
|
|
111
112
|
}
|
|
112
113
|
const IMAGE_URL_HEADER = "x-u1s1-image-url";
|
|
@@ -178,10 +179,8 @@ export async function generateImage(cfg, req, signal) {
|
|
|
178
179
|
}
|
|
179
180
|
if (resp.status === 401)
|
|
180
181
|
throw new Error("登录已失效,请重新运行 u1s1 login");
|
|
181
|
-
if (!resp.ok)
|
|
182
|
-
|
|
183
|
-
throw new Error(body?.error?.message ?? `图片生成服务返回 ${resp.status},稍后再试`);
|
|
184
|
-
}
|
|
182
|
+
if (!resp.ok)
|
|
183
|
+
throw new Error(await errorMessageFromResponse(resp, `图片生成服务返回 ${resp.status},稍后再试`));
|
|
185
184
|
return readGeneratedImageResponse(resp);
|
|
186
185
|
}
|
|
187
186
|
export async function fetchMe(cfg) {
|
|
@@ -200,6 +199,6 @@ export async function fetchMe(cfg) {
|
|
|
200
199
|
if (resp.status === 401)
|
|
201
200
|
throw new Error("登录已失效,请重新运行 u1s1 login");
|
|
202
201
|
if (!resp.ok)
|
|
203
|
-
throw new Error(`服务端返回 ${resp.status},稍后再试`);
|
|
202
|
+
throw new Error(await errorMessageFromResponse(resp, `服务端返回 ${resp.status},稍后再试`));
|
|
204
203
|
return (await resp.json());
|
|
205
204
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "u1s1-cli",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.9",
|
|
4
4
|
"description": "u1s1 — 有一说一,最省心的 AI 编程搭子。终端里用中文说需求,AI 帮你读文件、改代码、跑命令。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"license": "MIT",
|
|
43
43
|
"homepage": "https://u1s1.io",
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@earendil-works/pi-coding-agent": "0.84.
|
|
46
|
-
"@earendil-works/pi-tui": "0.84.
|
|
45
|
+
"@earendil-works/pi-coding-agent": "0.84.4",
|
|
46
|
+
"@earendil-works/pi-tui": "0.84.4",
|
|
47
47
|
"typebox": "1.3.7"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
package/scripts/patch-pi.js
CHANGED
|
@@ -133,13 +133,13 @@ const ENABLE_AUTOWRAP = "\\x1b[?7h";`,
|
|
|
133
133
|
expected: 1,
|
|
134
134
|
},
|
|
135
135
|
{
|
|
136
|
-
from: '
|
|
137
|
-
to: '
|
|
136
|
+
from: 'output.append("\\x1b[?2026h");',
|
|
137
|
+
to: 'output.append("\\x1b[?2026h" + DISABLE_AUTOWRAP);',
|
|
138
138
|
expected: 3,
|
|
139
139
|
},
|
|
140
140
|
{
|
|
141
|
-
from: '
|
|
142
|
-
to: '
|
|
141
|
+
from: 'output.append("\\x1b[?2026l");',
|
|
142
|
+
to: 'output.append(ENABLE_AUTOWRAP + "\\x1b[?2026l");',
|
|
143
143
|
expected: 3,
|
|
144
144
|
},
|
|
145
145
|
];
|