aihezu 2.8.10 → 2.8.11
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/commands/usage.js +17 -7
- package/package.json +1 -1
package/commands/usage.js
CHANGED
|
@@ -296,17 +296,27 @@ function usageHint(current, limit) {
|
|
|
296
296
|
}
|
|
297
297
|
|
|
298
298
|
function getUsageApiBase(baseUrl) {
|
|
299
|
-
// 去掉路径中的 /openai
|
|
300
|
-
//
|
|
299
|
+
// 去掉路径中的 /openai 或 /api 后缀
|
|
300
|
+
// - Codex base_url 常见格式 https://xxx/openai
|
|
301
|
+
// - 部分用户 base_url 为 https://xxx/api
|
|
302
|
+
// - Claude 默认 base_url 不带后缀,等价于 no-op
|
|
303
|
+
const stripSuffix = (pathname) => {
|
|
304
|
+
let p = pathname.replace(/\/+$/, '');
|
|
305
|
+
const lower = p.toLowerCase();
|
|
306
|
+
if (lower.endsWith('/openai')) {
|
|
307
|
+
p = p.slice(0, -'/openai'.length);
|
|
308
|
+
} else if (lower.endsWith('/api')) {
|
|
309
|
+
p = p.slice(0, -'/api'.length);
|
|
310
|
+
}
|
|
311
|
+
return p;
|
|
312
|
+
};
|
|
313
|
+
|
|
301
314
|
try {
|
|
302
315
|
const url = new URL(baseUrl);
|
|
303
|
-
|
|
304
|
-
if (pathname.toLowerCase().endsWith('/openai')) {
|
|
305
|
-
pathname = pathname.slice(0, -'/openai'.length);
|
|
306
|
-
}
|
|
316
|
+
const pathname = stripSuffix(url.pathname);
|
|
307
317
|
return `${url.origin}${pathname}`;
|
|
308
318
|
} catch (error) {
|
|
309
|
-
return baseUrl.replace(/\/+$/, '')
|
|
319
|
+
return stripSuffix(baseUrl.replace(/\/+$/, ''));
|
|
310
320
|
}
|
|
311
321
|
}
|
|
312
322
|
|