@forcome/ai-cli 0.1.0 → 0.1.1
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/bin/fai.js +3 -2
- package/package.json +3 -2
- package/src/index.js +13 -0
- package/src/index.test.js +19 -1
package/bin/fai.js
CHANGED
|
@@ -4,14 +4,15 @@
|
|
|
4
4
|
// 不用 isMain 守卫——本文件只作为 bin 运行(纯逻辑在 ../src/index.js)。
|
|
5
5
|
|
|
6
6
|
import { spawn } from 'node:child_process';
|
|
7
|
-
import { FORCOME_SERVER, resolveLhPath, resolveLhVersion } from '../src/index.js';
|
|
7
|
+
import { FORCOME_SERVER, resolveLhPath, resolveLhVersion, withLoginServer } from '../src/index.js';
|
|
8
8
|
|
|
9
9
|
// 默认指向 Forcome 门户(员工无需 --server);env LOBEHUB_SERVER 可覆盖(staging 等)
|
|
10
10
|
if (!process.env.LOBEHUB_SERVER) {
|
|
11
11
|
process.env.LOBEHUB_SERVER = FORCOME_SERVER;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
// lh 的 login 读 --server flag(不读 env,默认 app.lobehub.com)→ 必须显式注入,否则登错服务器
|
|
15
|
+
const args = withLoginServer(process.argv.slice(2), process.env.LOBEHUB_SERVER);
|
|
15
16
|
|
|
16
17
|
// wrapper 自身状态(不透传给 lh)
|
|
17
18
|
if (args[0] === '--forcome-version') {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forcome/ai-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Forcome AI 门户 CLI 薄壳——默认指向 ai.forcome.com,透传官方 @lobehub/cli (lh)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -45,5 +45,6 @@
|
|
|
45
45
|
},
|
|
46
46
|
"publishConfig": {
|
|
47
47
|
"access": "public"
|
|
48
|
-
}
|
|
48
|
+
},
|
|
49
|
+
"packageManager": "pnpm@9.7.0+sha1.8f12c476122faede7aed9a2126ef551c0dc65d7e"
|
|
49
50
|
}
|
package/src/index.js
CHANGED
|
@@ -25,3 +25,16 @@ export function resolveLhVersion() {
|
|
|
25
25
|
return 'unknown';
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* lh 的 `login` 命令读 `--server` 命令行参数(默认 OFFICIAL_SERVER_URL=app.lobehub.com),
|
|
31
|
+
* **不读 LOBEHUB_SERVER env**。其它命令(agent/gen/file)经 tRPC client 读 env,不受影响。
|
|
32
|
+
* 故 `fai login` 必须显式注入 `--server`,否则会登到 LobeHub 公有云而非我们的门户。
|
|
33
|
+
* 用户已带 `--server` 时不重复注入(允许覆盖到 staging 等)。
|
|
34
|
+
*/
|
|
35
|
+
export function withLoginServer(args, server) {
|
|
36
|
+
if (args[0] === 'login' && !args.includes('--server')) {
|
|
37
|
+
return ['login', '--server', server, ...args.slice(1)];
|
|
38
|
+
}
|
|
39
|
+
return args;
|
|
40
|
+
}
|
package/src/index.test.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { test } from 'node:test';
|
|
2
2
|
import assert from 'node:assert/strict';
|
|
3
|
-
import { resolveServerUrl, FORCOME_SERVER } from './index.js';
|
|
3
|
+
import { resolveServerUrl, FORCOME_SERVER, withLoginServer } from './index.js';
|
|
4
4
|
|
|
5
5
|
test('resolveServerUrl 默认指向 Forcome 门户', () => {
|
|
6
6
|
delete process.env.LOBEHUB_SERVER;
|
|
@@ -13,3 +13,21 @@ test('resolveServerUrl 受 LOBEHUB_SERVER env 覆盖(staging 等)', () => {
|
|
|
13
13
|
assert.equal(resolveServerUrl(), 'https://staging.forcome.com');
|
|
14
14
|
delete process.env.LOBEHUB_SERVER;
|
|
15
15
|
});
|
|
16
|
+
|
|
17
|
+
const SRV = 'https://ai.forcome.com';
|
|
18
|
+
|
|
19
|
+
test('withLoginServer: login 无 --server 时注入默认 server(避免登到 app.lobehub.com)', () => {
|
|
20
|
+
assert.deepEqual(withLoginServer(['login'], SRV), ['login', '--server', SRV]);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('withLoginServer: login 已带 --server 不重复注入(允许覆盖到 staging)', () => {
|
|
24
|
+
assert.deepEqual(
|
|
25
|
+
withLoginServer(['login', '--server', 'https://staging.forcome.com'], SRV),
|
|
26
|
+
['login', '--server', 'https://staging.forcome.com'],
|
|
27
|
+
);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('withLoginServer: 非 login 命令不动(agent/gen/file 走 env)', () => {
|
|
31
|
+
assert.deepEqual(withLoginServer(['agent', 'list'], SRV), ['agent', 'list']);
|
|
32
|
+
assert.deepEqual(withLoginServer(['gen', 'text', '-m', 'newapi/gpt-5.5'], SRV), ['gen', 'text', '-m', 'newapi/gpt-5.5']);
|
|
33
|
+
});
|