focalapi-cli 0.1.1 → 0.2.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/CHANGELOG.md +17 -0
- package/LICENSE +202 -202
- package/README.md +139 -209
- package/dist/cli.js +801 -223
- package/package.json +57 -50
- package/scripts/postinstall.cjs +41 -0
- package/skills/focalapi/SKILL.md +47 -43
- package/skills/focalapi-auth/SKILL.md +28 -50
- package/skills/focalapi-chat/SKILL.md +29 -29
- package/skills/focalapi-gen/SKILL.md +48 -79
- package/skills/focalapi-models/SKILL.md +49 -0
- package/skills/focalapi-task/SKILL.md +25 -0
- package/skills/focalapi-usage/SKILL.md +26 -36
package/README.md
CHANGED
|
@@ -1,209 +1,139 @@
|
|
|
1
|
-
<div align="center">
|
|
2
|
-
|
|
3
|
-
# focalapi-cli
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
[](https://www.npmjs.com/package/focalapi-cli)
|
|
8
|
-
[](./LICENSE)
|
|
9
|
-
[](https://nodejs.org)
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
##
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
focalapi --
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
focalapi
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
focalapi
|
|
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
|
-
focalapi
|
|
115
|
-
focalapi
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
focalapi connect install <agent-id> # 只装指定 Agent
|
|
141
|
-
focalapi connect uninstall # 按 manifest 精确卸载,不碰其他文件
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
`connect install` 把本仓库 [`skills/`](./skills) 下的技能包复制到各 Agent 的技能目录,并打印 provider 配置指引(把 Agent 的模型后端指向 focalapi)。技能装入后重启 Agent 会话,即可用自然语言驱动,例如「用 focalapi 画一张赛博朋克海报」。
|
|
145
|
-
|
|
146
|
-
## 面向 Agent 的设计约定
|
|
147
|
-
|
|
148
|
-
- 所有命令支持 `--json`:stdout 只输出 JSON(诊断走 stderr),可直接 `| jq`
|
|
149
|
-
- 非 TTY 环境自动禁用交互与动画,CI / 沙箱可无人值守运行
|
|
150
|
-
- 错误统一为 `{error: {code, message, hint}}` + 非零退出码
|
|
151
|
-
- API Key 绝不完整打印(一律 `sk-***尾4位` 脱敏)
|
|
152
|
-
|
|
153
|
-
## 命令入口
|
|
154
|
-
|
|
155
|
-
| 任务 | 命令 |
|
|
156
|
-
|---|---|
|
|
157
|
-
| 登录 / 状态 / 登出 | `focalapi auth login / status / logout` |
|
|
158
|
-
| DeepSeek 文本辅助 | `focalapi chat` |
|
|
159
|
-
| 图片 / 视频生成 | `focalapi gen image / gen video` |
|
|
160
|
-
| 任务查询与产物下载 | `focalapi task status / download`(图像任务使用 status 读取 `data[].url`) |
|
|
161
|
-
| 语音转写 / 合成 | `focalapi audio transcribe / speech` |
|
|
162
|
-
| 模型查询 | `focalapi models list / get` |
|
|
163
|
-
| 额度用量 | `focalapi usage` |
|
|
164
|
-
| 诊断排障 | `focalapi doctor` |
|
|
165
|
-
| Agent 接入 | `focalapi connect list / install / uninstall` |
|
|
166
|
-
| 版本与更新检查 | `focalapi version / update` |
|
|
167
|
-
| 原始只读 API 请求 | `focalapi request get /v1/models` |
|
|
168
|
-
|
|
169
|
-
每个命令都自带帮助:`focalapi <command> --help`。
|
|
170
|
-
|
|
171
|
-
### 原始只读请求
|
|
172
|
-
|
|
173
|
-
优先使用语义化命令(如 `models`、`chat`、`gen`)。当服务新增尚未封装的读取端点时,可使用:
|
|
174
|
-
|
|
175
|
-
```shell
|
|
176
|
-
focalapi request get /v1/models --json
|
|
177
|
-
focalapi request head /v1/models --json
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
该入口只接受站内路径与 `GET` / `HEAD`,不会隐藏任何写入操作。`--json` 时高阶命令通常直通上游响应;`request` 固定返回 `{ method, path, status, content_type, data }` 信封,错误仍为 `{ error: { code, message, hint? } }`,且不会输出完整 API Key。
|
|
181
|
-
|
|
182
|
-
## 配置
|
|
183
|
-
|
|
184
|
-
- 配置文件:`~/.focalapi/config.json`(权限 600),支持多 profile(`--profile`)
|
|
185
|
-
- 环境变量:`FOCALAPI_API_KEY`、`FOCALAPI_BASE_URL`、`FOCALAPI_MODEL`、`FOCALAPI_CONFIG_DIR`
|
|
186
|
-
- 优先级:命令行 flag > 环境变量 > 配置文件
|
|
187
|
-
|
|
188
|
-
## 本地 e2e 验证清单(需要真实 Key)
|
|
189
|
-
|
|
190
|
-
```shell
|
|
191
|
-
focalapi auth login --key sk-xxxx
|
|
192
|
-
focalapi doctor # 全 ✓
|
|
193
|
-
focalapi chat "你好" -m focal-rehearsal-chat # 免费演练模型
|
|
194
|
-
focalapi gen image "测试图" -m <图像模型> -o ./out
|
|
195
|
-
focalapi gen video "测试视频" -m <视频模型> --no-wait --json
|
|
196
|
-
focalapi task download <task_id>
|
|
197
|
-
focalapi connect install && focalapi connect uninstall # 幂等且清理干净
|
|
198
|
-
```
|
|
199
|
-
|
|
200
|
-
## 链接
|
|
201
|
-
|
|
202
|
-
- focalapi:<https://focalapi.com>
|
|
203
|
-
- Gitee:<https://gitee.com/xnn-ai/focalapi-cli>
|
|
204
|
-
- npm:<https://www.npmjs.com/package/focalapi-cli>
|
|
205
|
-
- 内置 Skills:[`./skills`](./skills)
|
|
206
|
-
|
|
207
|
-
## License
|
|
208
|
-
|
|
209
|
-
[Apache-2.0](./LICENSE)
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# focalapi-cli
|
|
4
|
+
|
|
5
|
+
**Give any AI Agent direct access to FocalAPI creative models**
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/focalapi-cli)
|
|
8
|
+
[](./LICENSE)
|
|
9
|
+
[](https://nodejs.org)
|
|
10
|
+
|
|
11
|
+
```shell
|
|
12
|
+
npm i -g focalapi-cli
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
</div>
|
|
16
|
+
|
|
17
|
+
focalapi-cli turns FocalAPI's creative-model gateway into commands and Skills that an Agent can run directly. Users describe the outcome they want; the Agent does not need to probe models, guess parameters, handcraft requests, or switch platforms first.
|
|
18
|
+
|
|
19
|
+
It does not configure FocalAPI as the Agent's primary model or provider. Agents such as Codex, Claude Code, and Cursor keep their existing reasoning models and call FocalAPI only for creative tasks such as image and video generation.
|
|
20
|
+
|
|
21
|
+
## Connect in three steps
|
|
22
|
+
|
|
23
|
+
```shell
|
|
24
|
+
# 1. Install. Skills are synchronized automatically when lifecycle scripts are allowed.
|
|
25
|
+
npm i -g focalapi-cli
|
|
26
|
+
|
|
27
|
+
# 2. Configure a FocalAPI key.
|
|
28
|
+
focalapi auth login --key sk-xxxx
|
|
29
|
+
|
|
30
|
+
# 3. Connect every detected Agent, then verify the installation. The operation is idempotent.
|
|
31
|
+
focalapi connect
|
|
32
|
+
focalapi connect verify --json
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Create a key at <https://focalapi.com/console/token>. CI and sandbox environments can use `FOCALAPI_API_KEY`; self-hosted deployments can set `FOCALAPI_BASE_URL`.
|
|
36
|
+
|
|
37
|
+
If an npm security policy blocks lifecycle scripts, run `focalapi connect` explicitly. This is also the stable manual integration entry point. Set `FOCALAPI_SKIP_POSTINSTALL=1` to intentionally skip automatic post-install integration.
|
|
38
|
+
|
|
39
|
+
## Zero-guesswork Agent workflows
|
|
40
|
+
|
|
41
|
+
When no model is specified, the CLI reads the live model pool and detailed model contract available to the current key, selects the maintained FocalAPI default, and sends only one real generation request.
|
|
42
|
+
|
|
43
|
+
```shell
|
|
44
|
+
# Automatically select the current default image model.
|
|
45
|
+
focalapi gen image "Product hero image, soft studio lighting" -o ./out --json
|
|
46
|
+
|
|
47
|
+
# Automatically select the current default video model and return a task ID immediately.
|
|
48
|
+
focalapi gen video "Ocean waves hitting rocks, cinematic" --no-wait -o ./out --json
|
|
49
|
+
|
|
50
|
+
# Continue from next_command in the generation response without resubmitting the task.
|
|
51
|
+
focalapi task status <task-id> --json
|
|
52
|
+
focalapi task download <task-id> -o ./out --json
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
When the user specifies a model, read its authoritative contract first:
|
|
56
|
+
|
|
57
|
+
```shell
|
|
58
|
+
focalapi models get <model-id> --json
|
|
59
|
+
focalapi gen image "<prompt>" -m <model-id> [contract-supported options] -o ./out --json
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
The CLI can also resolve a model without generating anything:
|
|
63
|
+
|
|
64
|
+
```shell
|
|
65
|
+
focalapi models resolve image --json
|
|
66
|
+
focalapi models resolve video --json
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
`resolve` returns the exact `model.id`, verified `endpoint_type`, complete `supported_params`, candidate models, and a `next_command`. When a list summary and detailed contract disagree, the detailed contract is authoritative.
|
|
70
|
+
|
|
71
|
+
## Agent integration
|
|
72
|
+
|
|
73
|
+
```shell
|
|
74
|
+
focalapi connect # Install or repair every detected Agent.
|
|
75
|
+
focalapi connect list # Inspect supported, detected, and installed targets.
|
|
76
|
+
focalapi connect install codex cursor # Install for selected Agents.
|
|
77
|
+
focalapi connect install --path <dir> # Install to an unlisted or project-level Skills directory.
|
|
78
|
+
focalapi connect verify --json # Verify Skill integrity and authentication readiness.
|
|
79
|
+
focalapi connect uninstall # Remove only managed Skills that the user has not modified.
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
The built-in catalog currently covers 44 Agent targets, including Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, OpenCode, OpenClaw, Cline, Windsurf, Warp, Trae, Qwen Code, Kimi CLI, and Hermes. Targets such as Codex, Cline, Pi, and Warp that share `~/.agents/skills` are deduplicated by path, so the Skills are installed only once.
|
|
83
|
+
|
|
84
|
+
Installation is transactional: the current `focalapi-*` catalog is written as one unit, and any failed step rolls back the operation. The manifest records a SHA-256 directory digest for each Skill. By default, uninstall removes only managed Skills whose digest has not changed and preserves user-modified content.
|
|
85
|
+
|
|
86
|
+
The Skill routing contract requires Agents to:
|
|
87
|
+
|
|
88
|
+
- trigger FocalAPI for creative tasks even when the user does not name it;
|
|
89
|
+
- omit `--model` when no model is specified, letting the CLI select one without generating test samples;
|
|
90
|
+
- use only the live parameter contract returned by `models get` for an explicitly selected model;
|
|
91
|
+
- reuse the original `task_id` for asynchronous work instead of charging for duplicate submissions while a task is `pending`;
|
|
92
|
+
- return to the original task after resolving an authentication error rather than stopping at diagnostics.
|
|
93
|
+
|
|
94
|
+
## Current capability boundary
|
|
95
|
+
|
|
96
|
+
The fully validated automatic generation paths currently cover images and video, including image editing, reference-image creation, text-to-video, and image-to-video. The CLI retains text and audio commands, but an Agent may use them only when both the live model details and CLI help expose an executable contract. It never infers future audio, 3D, or other modality support from model names alone.
|
|
97
|
+
|
|
98
|
+
## Stable output for Agents
|
|
99
|
+
|
|
100
|
+
- All automation commands support `--json`; stdout contains JSON only, while progress and diagnostics go to stderr.
|
|
101
|
+
- Errors use `{ error: { code, message, hint, request_id? } }`.
|
|
102
|
+
- API keys are always redacted.
|
|
103
|
+
- Image results return local `files`; asynchronous video results return `task_id` and `next_command`.
|
|
104
|
+
- Local validation rejects known invalid billing multipliers and model parameters before sending a request.
|
|
105
|
+
|
|
106
|
+
## Command map
|
|
107
|
+
|
|
108
|
+
| Task | Command |
|
|
109
|
+
| --- | --- |
|
|
110
|
+
| Generate images with automatic or explicit model selection | `focalapi gen image` |
|
|
111
|
+
| Generate video with automatic or explicit model selection | `focalapi gen video` |
|
|
112
|
+
| Resolve models and inspect live contracts | `focalapi models resolve/get/search/list` |
|
|
113
|
+
| Check and download asynchronous tasks | `focalapi task status/download` |
|
|
114
|
+
| Sign in and inspect key status | `focalapi auth login/status/logout` |
|
|
115
|
+
| Inspect quota, usage, and diagnostics | `focalapi usage`, `focalapi doctor` |
|
|
116
|
+
| Connect Agent Skills | `focalapi connect` |
|
|
117
|
+
| Make read-only raw API requests | `focalapi request get/head` |
|
|
118
|
+
|
|
119
|
+
Every command includes built-in help: `focalapi <command> --help`.
|
|
120
|
+
|
|
121
|
+
## Development validation
|
|
122
|
+
|
|
123
|
+
```shell
|
|
124
|
+
npm install
|
|
125
|
+
npx tsc --noEmit
|
|
126
|
+
npm run build
|
|
127
|
+
npm test
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Links
|
|
131
|
+
|
|
132
|
+
- FocalAPI: <https://focalapi.com>
|
|
133
|
+
- GitHub: <https://github.com/focalapi/focalapi-cli>
|
|
134
|
+
- npm: <https://www.npmjs.com/package/focalapi-cli>
|
|
135
|
+
- Bundled Skills: [`./skills`](./skills)
|
|
136
|
+
|
|
137
|
+
## License
|
|
138
|
+
|
|
139
|
+
[Apache-2.0](./LICENSE)
|