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/README.md CHANGED
@@ -1,209 +1,139 @@
1
- <div align="center">
2
-
3
- # focalapi-cli
4
-
5
- **给你的 AI Agent 赋予 focalapi 的创作模型能力**
6
-
7
- [![npm](https://img.shields.io/npm/v/focalapi-cli?color=brightgreen&label=npm)](https://www.npmjs.com/package/focalapi-cli)
8
- [![license](https://img.shields.io/badge/license-Apache--2.0-blue)](./LICENSE)
9
- [![node](https://img.shields.io/badge/node-%3E%3D18-brightgreen)](https://nodejs.org)
10
-
11
- focalapi 的图像、视频、音频与视觉创作能力,可以通过 focalapi CLI + Skills 交给本地 Agent 调用;DeepSeek 仅作为提示词、分镜和轻量文本的备用能力。
12
-
13
- ```shell
14
- npm i -g focalapi-cli
15
- ```
16
-
17
- </div>
18
-
19
- ---
20
-
21
- ## focalapi-cli 能做什么
22
-
23
- 让你的 AI Agent 具备这些 focalapi 能力,并能在复杂任务中组合调用:
24
-
25
- - **图片 / 视频生成**:文生图、图生图、文生视频,产物自动下载到本地;视频任务支持异步编排
26
- - **音频**:语音转写(transcribe)、文字转语音(speech)
27
- - **DeepSeek 文本辅助**:提示词、分镜、旁白和轻量脚本草稿
28
- - **Agent 接入**:`focalapi connect` 把内置 Skills 装进本机 Agent,Agent 即刻学会调用 focalapi
29
- - **治理闭环**:`usage` 额度用量、`doctor` 只读诊断(用免费演练模型做端到端自检,不花额度)
30
-
31
- ## 为什么需要 focalapi-cli
32
-
33
- focalapi-cli 不是让你记住更多命令,而是把 focalapi 的模型能力变成 Agent 可以调用的工具箱。
34
-
35
- ```text
36
- 接入链路:
37
- 安装 CLI -> 登录(sk- key)-> connect 注入 Agent Skills -> Agent 自然语言调用能力
38
-
39
- 调用链路(Agent 视角):
40
- models list 选模型
41
- -> gen / audio / chat(DeepSeek 备用)调用
42
- -> 产物落盘(图像/视频/音频)
43
- -> usage 看额度,doctor 做诊断
44
- ```
45
-
46
- ## 安装与初始化
47
-
48
- ```shell
49
- # 1. 安装 CLI(Node.js >= 18)
50
- npm i -g focalapi-cli
51
- focalapi --version
52
-
53
- # 2. 登录(Key 在 https://focalapi.com/console/token 创建)
54
- focalapi auth login --key sk-xxxx
55
-
56
- # 3. 自检(使用免费演练模型 focal-rehearsal-chat,不消耗额度)
57
- focalapi doctor
58
-
59
- # 4. focalapi Skills 同步到本机 Agent
60
- focalapi connect install
61
- ```
62
-
63
- 无终端交互的环境(CI、Agent 沙箱)用环境变量即可:
64
-
65
- ```shell
66
- export FOCALAPI_API_KEY=sk-xxxx
67
- # 私有化部署时:export FOCALAPI_BASE_URL=https://你的域名
68
- ```
69
-
70
- ## 常用任务
71
-
72
- ### DeepSeek 文本辅助
73
-
74
- ```shell
75
- focalapi chat "把这个产品简介写成 6 镜头分镜" -m <DeepSeek模型>
76
-
77
- cat brief.md | focalapi chat -m <DeepSeek模型> --system "你是专业的广告分镜师"
78
-
79
- focalapi chat "提炼这张参考图的构图和色彩" -m <DeepSeek模型> --input @photo.jpg
80
- ```
81
-
82
- ### 生成图片 / 视频
83
-
84
- ```shell
85
- # 先读取模型的端点、支持参数、默认值与范围;适合 Agent 在生成前自检
86
- focalapi models get doubao-seedream-4-5-251128
87
- focalapi models get doubao-seedance-2-0-260128 --json
88
-
89
- focalapi gen image "未来城市海报" -m <图像模型> --size 1024x1024 -o ./out
90
- focalapi gen image "产品主视觉" -m gpt-image-2 --size 1536x1024 --quality high --background opaque -o ./out
91
- focalapi gen image "将背景改为雨夜" -m gpt-image-2 --image https://example.com/source.png \
92
- --mask https://example.com/mask.png --response-format b64_json -o ./out
93
- # OpenAI 图像模型可选持久任务:立即获得 task_id,稍后查询 data[].url
94
- focalapi gen image "产品主视觉" -m gpt-image-2 --size 1024x1024 --no-wait --json
95
- focalapi task status <task_id> --json
96
-
97
- # Gemini 图像模型是原生 Gemini 端点,不走 OpenAI 图像端点
98
- focalapi gen gemini-image "一只水彩风格的橘猫" -m gemini-3.1-flash-image-preview \
99
- --aspect-ratio 16:9 --image-size 2K -o ./out
100
- # Gemini native generationConfig fields can be passed through --config; named flags cover --image, --system, --seed, --thinking-level, --temperature, and --top-p. responseFormat.image and a single candidate are fixed.
101
-
102
- # 视频:默认等待完成并下载;异步编排用 --no-wait
103
- focalapi gen video "海浪拍打礁石" -m <视频模型> --seconds 5
104
- focalapi gen video "海浪拍打礁石" -m doubao-seedance-2-0-260128 \
105
- --seconds 5 --resolution 720p --ratio 16:9 --generate-audio true --no-wait --json
106
- focalapi gen video "让海浪缓慢推进" -m doubao-seedance-2-0-260128 \
107
- --image https://example.com/frame.png --generate-audio false --watermark true \
108
- --return-last-frame true --callback-url https://example.com/callback \
109
- --execution-expires-after 7200 --safety-identifier customer-42 --priority 4 --no-wait --json
110
- # Ark-compatible content (text, image_url, video_url, audio_url with roles) is available unchanged through metadata.content:
111
- focalapi gen video "ignored when content is supplied" -m doubao-seedance-2-0-260128 \
112
- --content '[{"type":"text","text":"A cinematic ocean wave."}]' --no-wait --json
113
- focalapi gen video "海浪拍打礁石" -m <视频模型> --no-wait --json # task_id
114
- focalapi task status <task_id> --json
115
- focalapi task download <task_id> -o ./out
116
- ```
117
-
118
- `models get` 是生成前的权威检查入口:返回 `supported_endpoint_types`、`supported_params`,并在可用时提供官方文档链接。CLI 会在本地拒绝已知的不支持参数,例如 Seedream 4.5 的低于 3.69 MP 的尺寸、Seedance Fast/Mini 的 1080p、或 Seedance 的非 4–15 秒时长;不会把这些确定会失败的请求交给上游。同步图像生成时,等待进度输出到 stderr,因此 `--json` 的 stdout 始终保持为可解析 JSON。
119
-
120
- ### 音频创作
121
-
122
- ```shell
123
- focalapi audio transcribe meeting.mp3 -m <转写模型>
124
- focalapi audio speech "大家好" -m <TTS模型> -o hello.mp3
125
- ```
126
-
127
- ### 额度与诊断
128
-
129
- ```shell
130
- focalapi usage # 令牌额度 + 本周期账单用量
131
- focalapi auth status # Key 有效性、来源、过期时间
132
- focalapi doctor # 全链路只读诊断,任何调用失败先跑它
133
- ```
134
-
135
- ## Agent 接入(connect)
136
-
137
- ```shell
138
- focalapi connect list # 探测本机已支持的 Agent
139
- focalapi connect install # 向全部检测到的 Agent 安装 skills
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
+ [![npm](https://img.shields.io/npm/v/focalapi-cli?color=brightgreen&label=npm)](https://www.npmjs.com/package/focalapi-cli)
8
+ [![license](https://img.shields.io/badge/license-Apache--2.0-blue)](./LICENSE)
9
+ [![node](https://img.shields.io/badge/node-%3E%3D18-brightgreen)](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)