@forcome/ai-cli 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Forcome
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # @forcome/ai-cli (`fai`)
2
+
3
+ Forcome AI 门户命令行——默认指向 https://ai.forcome.com,透传官方 [`@lobehub/cli`](https://www.npmjs.com/package/@lobehub/cli)(`lh`)。
4
+ 员工无需每次 `--server`;装好直接 `fai login` 走钉钉扫码授权。
5
+
6
+ ## 安装(开发员工)
7
+
8
+ ```bash
9
+ npm i -g @forcome/ai-cli
10
+ fai login # 浏览器钉钉扫码授权(首次)
11
+ fai agent list # 列助理
12
+ fai gen text -m newapi/gpt-5.5 --stream "你好" # 生成文本(必须显式 newapi 模型 + --stream)
13
+ ```
14
+
15
+ ## 自动化 / CI(headless)
16
+
17
+ Web 登录 → 设置 → API Keys 建一个 key:
18
+
19
+ ```bash
20
+ LOBEHUB_CLI_API_KEY=<key> fai gen text -m newapi/gpt-5.5 --stream "..."
21
+ ```
22
+
23
+ API key 模式仅支持 tRPC 命令(`agent` / `gen` / `provider` / `model`);`file` 类命令走 `/webapi/*` 不接受 API key,需先 `fai login`。
24
+
25
+ ## 覆盖默认服务器(staging / 自建)
26
+
27
+ ```bash
28
+ LOBEHUB_SERVER=https://staging.forcome.com fai login
29
+ ```
30
+
31
+ ## 已知限制(phase 1)
32
+
33
+ - `lh gen text` 默认模型 `openai/gpt-4o-mini` 在本门户不可用(`ENABLED_OPENAI=0`)——**必须 `-m newapi/<model>`**,且加 `--stream`(非 stream 模式 server 返 SSE 流致 JSON 解析失败)。可用模型见 `fai model list newapi`。
34
+ - `fai agent run`(实时 agent 执行)、`fai connect`(设备配对)依赖未部署的 agent-gateway / device-gateway,暂不支持。
35
+
36
+ ## 排障
37
+
38
+ - `lh login` 的授权 URL 是 `http://192.168.16.157/...`(内网 IP)→ nginx `/oidc/` location 强制头丢了,见 [troubleshooting §8.109](../docs/troubleshooting.md)。
39
+ - `fai: command not found` 或 `未找到 lh 命令` → 先 `npm i -g @lobehub/cli`(`fai` 依赖它)。
40
+ - `agent list` 报 procedure not found → CLI 与 server tRPC 版本漂移,pin 与当前 server 同源的 `@lobehub/cli`。
41
+
42
+ ## 实现
43
+
44
+ 不改 `lh` 源码——本包仅设置 `LOBEHUB_SERVER` 默认值后 `spawn('lh', argv)` 透传,`@lobehub/cli` 作为 `dependency` 自动跟随上游升级。
package/bin/fai.js ADDED
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env node
2
+ // @forcome/ai-cli bin 入口(命令 fai)
3
+ // 默认指向 https://ai.forcome.com,透传给官方 @lobehub/cli (lh)。
4
+ // 不用 isMain 守卫——本文件只作为 bin 运行(纯逻辑在 ../src/index.js)。
5
+
6
+ import { spawn } from 'node:child_process';
7
+ import { FORCOME_SERVER, resolveLhPath, resolveLhVersion } from '../src/index.js';
8
+
9
+ // 默认指向 Forcome 门户(员工无需 --server);env LOBEHUB_SERVER 可覆盖(staging 等)
10
+ if (!process.env.LOBEHUB_SERVER) {
11
+ process.env.LOBEHUB_SERVER = FORCOME_SERVER;
12
+ }
13
+
14
+ const args = process.argv.slice(2);
15
+
16
+ // wrapper 自身状态(不透传给 lh)
17
+ if (args[0] === '--forcome-version') {
18
+ console.log(`forcome-ai-cli → ${process.env.LOBEHUB_SERVER} (wraps @lobehub/cli ${resolveLhVersion()})`);
19
+ process.exit(0);
20
+ }
21
+
22
+ // 自包含:resolve 打包的 lh 入口,用 node 跑
23
+ let lhPath;
24
+ try {
25
+ lhPath = resolveLhPath();
26
+ } catch {
27
+ console.error('未找到 @lobehub/cli 依赖。重装:npm i -g @forcome/ai-cli');
28
+ process.exit(127);
29
+ }
30
+
31
+ // 透传:继承 stdio(交互/流式/颜色/TTY)与 exit code/signal
32
+ const child = spawn(process.execPath, [lhPath, ...args], { stdio: 'inherit', env: process.env });
33
+
34
+ child.on('error', (e) => {
35
+ console.error('启动 lh 失败:', e.message);
36
+ process.exit(1);
37
+ });
38
+
39
+ child.on('exit', (code, signal) => {
40
+ if (signal) process.kill(process.pid, signal);
41
+ process.exit(code ?? 0);
42
+ });
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@forcome/ai-cli",
3
+ "version": "0.1.0",
4
+ "description": "Forcome AI 门户 CLI 薄壳——默认指向 ai.forcome.com,透传官方 @lobehub/cli (lh)",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "author": "Forcome",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/Forcome-Database/Forcome-AI.git",
11
+ "directory": "cli"
12
+ },
13
+ "homepage": "https://github.com/Forcome-Database/Forcome-AI/tree/master/cli#readme",
14
+ "bugs": {
15
+ "url": "https://github.com/Forcome-Database/Forcome-AI/issues"
16
+ },
17
+ "keywords": [
18
+ "lobehub",
19
+ "lobehub-cli",
20
+ "ai",
21
+ "cli",
22
+ "forcome"
23
+ ],
24
+ "bin": {
25
+ "fai": "./bin/fai.js"
26
+ },
27
+ "exports": {
28
+ ".": "./src/index.js"
29
+ },
30
+ "files": [
31
+ "bin",
32
+ "src",
33
+ "README.md",
34
+ "LICENSE"
35
+ ],
36
+ "scripts": {
37
+ "test": "node --test src/index.test.js",
38
+ "smoke": "node bin/fai.js --forcome-version"
39
+ },
40
+ "dependencies": {
41
+ "@lobehub/cli": "0.0.37"
42
+ },
43
+ "engines": {
44
+ "node": ">=20"
45
+ },
46
+ "publishConfig": {
47
+ "access": "public"
48
+ }
49
+ }
package/src/index.js ADDED
@@ -0,0 +1,27 @@
1
+ // @forcome/ai-cli — 纯导出模块(无副作用,可被测试/bin 入口 import)
2
+ // 默认指向 https://ai.forcome.com,resolve 打包的 @lobehub/cli(自包含,不依赖全局 PATH lh)。
3
+
4
+ import { createRequire } from 'node:module';
5
+
6
+ const require = createRequire(import.meta.url);
7
+
8
+ export const FORCOME_SERVER = 'https://ai.forcome.com';
9
+
10
+ /** 解析目标 server:env LOBEHUB_SERVER 优先,否则默认 Forcome 门户。 */
11
+ export function resolveServerUrl() {
12
+ return process.env.LOBEHUB_SERVER || FORCOME_SERVER;
13
+ }
14
+
15
+ /** 从依赖解析官方 lh 入口(自包含,不依赖全局 PATH)。 */
16
+ export function resolveLhPath() {
17
+ return require.resolve('@lobehub/cli/dist/index.js');
18
+ }
19
+
20
+ /** 取打包的 lh 版本(诊断/展示用,失败返 unknown)。 */
21
+ export function resolveLhVersion() {
22
+ try {
23
+ return require('@lobehub/cli/package.json').version;
24
+ } catch {
25
+ return 'unknown';
26
+ }
27
+ }
@@ -0,0 +1,15 @@
1
+ import { test } from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { resolveServerUrl, FORCOME_SERVER } from './index.js';
4
+
5
+ test('resolveServerUrl 默认指向 Forcome 门户', () => {
6
+ delete process.env.LOBEHUB_SERVER;
7
+ assert.equal(resolveServerUrl(), FORCOME_SERVER);
8
+ assert.equal(resolveServerUrl(), 'https://ai.forcome.com');
9
+ });
10
+
11
+ test('resolveServerUrl 受 LOBEHUB_SERVER env 覆盖(staging 等)', () => {
12
+ process.env.LOBEHUB_SERVER = 'https://staging.forcome.com';
13
+ assert.equal(resolveServerUrl(), 'https://staging.forcome.com');
14
+ delete process.env.LOBEHUB_SERVER;
15
+ });