imgrelay 0.0.0-stage → 0.2.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.md ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-PRESENT Anthony Fu <https://github.com/antfu>
4
+ Copyright (c) 2026-PRESENT BINGWU2003 <https://github.com/BINGWU2003>
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,192 @@
1
- # Temporary Holding Version
1
+ # ImgRelay
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ 通过统一 CLI 和 Codex Skill 调用多家 OpenAI Images 兼容中转站。用户级配置跨项目复用,
4
+ 生成结果默认保存在当前工作目录的 `output/imagegen/`。
5
+
6
+ 首版支持文生图、供应商与凭据管理、模型列表缓存、只读检查、原图保存和 JSON 输出。
7
+ 图片编辑、Responses、Chat Completions 与非标准异步协议属于后续范围。
8
+
9
+ ## 安装与开发
10
+
11
+ 需要 Node.js 22.20+(22.x)或 24.x。发布到 npm 后:
12
+
13
+ ```bash
14
+ npm install -g imgrelay
15
+ npx skills add bingwu-devkit/imgrelay --skill imgrelay --agent codex --global --copy
16
+ ```
17
+
18
+ CLI 与 Skill 分开安装;npm 安装不会改动 Codex 配置。当前源码可直接构建运行:
19
+
20
+ ```bash
21
+ pnpm install
22
+ pnpm build
23
+ node packages/cli/dist/index.mjs --help
24
+ npx skills add ./skills --skill imgrelay --agent codex --global --copy
25
+ ```
26
+
27
+ 开发使用 pnpm 11.15.1。以下示例中的 `imgrelay` 可替换为上述 Node 命令。
28
+
29
+ ## 首次配置
30
+
31
+ 交互式配置直接隐藏输入密钥并保存到 `config.json`,随后查询模型列表并设置默认项。
32
+ 查询失败时可手动填入模型 ID,配置流程不生成图片:
33
+
34
+ ```bash
35
+ imgrelay provider add cubence --preset cubence
36
+ imgrelay provider use cubence
37
+ imgrelay doctor --provider cubence
38
+ ```
39
+
40
+ 修改密钥同样使用交互式隐藏输入,留空保留当前密钥:
41
+
42
+ ```bash
43
+ imgrelay provider edit cubence
44
+ ```
45
+
46
+ 新增供应商和输入新密钥须在交互终端中运行,不加 `--json`。密钥明文保存在配置中,
47
+ 不要求以 `sk-` 开头;删除供应商会一并移除其密钥。
48
+ 非交互命令可修改已有供应商的其他参数或显式清除密钥:
49
+
50
+ ```bash
51
+ imgrelay provider edit cubence --model vendor-model --json
52
+ imgrelay provider edit cubence --clear-key --json
53
+ ```
54
+
55
+ ## 命令
56
+
57
+ | 命令 | 用途 |
58
+ | -------------------------------------- | ----------------------------------------- |
59
+ | `provider add <名称>` | 添加供应商;可显式选择 `--preset cubence` |
60
+ | `provider list` | 列出摘要及默认项 |
61
+ | `provider show <名称>` | 查看脱敏配置 |
62
+ | `provider edit <名称>` | 修改配置与凭据,`--clear-key` 清除凭据 |
63
+ | `provider use <名称>` | 设置默认供应商 |
64
+ | `provider remove <名称>` | 移除供应商及配置中保存的密钥 |
65
+ | `models [--provider 名称] [--refresh]` | 查询模型或查看 15 分钟缓存 |
66
+ | `doctor [--provider 名称]` | 检查配置、鉴权和模型查询,不生成图片 |
67
+ | `generate` | 生成并保存图片及记录 |
68
+
69
+ 所有命令支持 `--json` 和 `--help`,根命令支持 `--version`。
70
+ JSON 模式禁用交互,标准输出仅包含一个最终 JSON,进度在标准错误。
71
+
72
+ ## 生成图片
73
+
74
+ ```bash
75
+ imgrelay generate --prompt "一只戴宇航员头盔的猫"
76
+ imgrelay generate --prompt "一只戴宇航员头盔的猫" --provider cubence --n 2 --json
77
+ imgrelay generate --prompt "一只戴宇航员头盔的猫" --model vendor-model --size auto --quality high --output-format png
78
+ imgrelay generate --prompt "一只戴宇航员头盔的猫" --output-dir ./images --filename cat.png --timeout 600
79
+ ```
80
+
81
+ 生成时必须通过 `--prompt` 提供非空文本。CLI 原样发送内容,保留换行及首尾空白,
82
+ 不自动添加风格或约束。长提示词也通过此选项传递,按当前 shell 正确引用以保留特殊字符。
83
+
84
+ 单次参数覆盖不会改动持久配置。参数值按“命令 → 供应商默认 → 工具默认”合并;
85
+ 工具仅默认数量为 1,不强制尺寸、质量或格式。未知模型允许调用,模型列表缺失不阻断生成。
86
+
87
+ 图片保留原始字节;Base64 优先于 URL,图片下载及重定向不带 API Key。
88
+ 记录实际格式、尺寸和字节数。默认文件名包含 UUID 和序号;自定义文件名的扩展名按实际格式,
89
+ 多图追加序号。默认不覆盖文件,显式 `--overwrite` 才允许覆盖。
90
+
91
+ 默认生成超时为 600 秒;只读请求最多重试一次,生成 POST 不自动重试。
92
+ 超时或断网意味着结果未知,上游可能仍在生成。不会自动换模型、降参数或拆成多次付费请求。
93
+ 每张图片最多 32 MiB,上游 JSON 最多 128 MiB;某项失败后继续保存其他结果。
94
+
95
+ ## 中转站兼容配置
96
+
97
+ 同协议中转站通过 `provider add` 接入,不新增品牌客户端。
98
+ Base URL 支持主机地址、`/v1`、自定义前缀及标准完整生成 URL,并集中处理路径拼接。
99
+ `doctor` 展示最终地址;认证模型接口成功只证明模型查询可用,不证明生成及全部参数可用。
100
+
101
+ `provider add/edit` 还支持 `--generation-path`、`--models-path`、默认生成参数、
102
+ `--timeout` 和 `--capabilities-file`。端点覆盖仅接受路径,不能更换主机。
103
+ 能力覆盖文件是按模型 ID 索引的 JSON:
104
+
105
+ ```json
106
+ {
107
+ "vendor-model": {
108
+ "source": "provider_override",
109
+ "parameters": {
110
+ "n": { "min": 1, "max": 1 },
111
+ "quality": { "values": ["high"] },
112
+ "outputFormat": { "values": ["png", "webp"] },
113
+ "responseFormat": { "supported": false }
114
+ }
115
+ }
116
+ }
117
+ ```
118
+
119
+ 校验按“供应商覆盖 → 已知模型能力 → 上游验证”执行,显式命令参数同样受覆盖约束。
120
+ 内置 GPT Image 1/mini 的已知参数;供应商可覆盖具体差异。Cubence 预设来自需求中的一次
121
+ 成功调用,仅提供默认组合,不推断其全部能力。GPT Image 默认不发送 `response_format`;
122
+ 确需配置兼容返回格式的站点可通过供应商默认值与能力覆盖明确表达。
123
+
124
+ ## 配置与输出
125
+
126
+ Windows、Linux 和 macOS 的配置目录统一为当前用户主目录下的 `~/.imgrelay/`。
127
+ `IMGRELAY_CONFIG_DIR` 可覆盖目录,相对路径基于当前工作目录解析。
128
+
129
+ 供应商配置与明文 API Key 集中保存在版本 1 的 `config.json`,模型缓存保存在同目录的
130
+ `models-cache.json`。文件使用系统默认权限,不做加密、专用 ACL 或权限校验。
131
+ 隐藏输入的密钥保存在供应商的 `apiKey` 字段。配置结构例如:
132
+
133
+ ```json
134
+ {
135
+ "schemaVersion": 1,
136
+ "defaultProvider": "relay",
137
+ "providers": {
138
+ "relay": {
139
+ "protocol": "openai-images",
140
+ "baseUrl": "https://relay.example/v1",
141
+ "apiKey": "your-api-key",
142
+ "defaultModel": "vendor-model"
143
+ }
144
+ }
145
+ }
146
+ ```
147
+
148
+ 模型缓存索引为供应商、配置修订、端点和实际凭据的 SHA-256 摘要,地址或实际凭据变化后
149
+ 不会复用旧查询。CLI 输出、日志、JSON 和生成记录保持脱敏,不保存密钥明文、鉴权头、
150
+ 原始 Base64 或带访问凭据的下载链接。图片和生成记录默认保存在当前工作目录的
151
+ `output/imagegen/`,可通过 `--output-dir` 指定。
152
+ 生成记录含提示词及请求参数,应按本机文件管理方式处理。
153
+
154
+ JSON 外层固定为 `schemaVersion`、`command`、`status`、`data`、`error`。
155
+ 生成结果的 `data.images` 包含本地路径、实际格式/尺寸/字节数,另有请求模型、上游报告模型
156
+ (仅在返回时)、失败项、用量和 `recordPath`。使用 `error.category` 判断失败类型。
157
+ 请求提交前保存记录,单项保存失败保留其他图片,记录保存失败仍返回已保存路径。
158
+ `data.endpoint` 是本次实际生成地址,`data.capabilityEvidence` 保留已知模型与供应商覆盖的
159
+ 来源及已有验证时间;未知能力显示为空,不从一次成功调用推断其他能力。
160
+
161
+ | 退出码 | 含义 |
162
+ | ------ | ------------------------------------ |
163
+ | 0 | 成功 |
164
+ | 1 | 内部错误 |
165
+ | 2 | 输入、配置、凭据或本地能力校验错误 |
166
+ | 3 | 上游错误、无效图片响应或生成结果未知 |
167
+ | 4 | 图片或记录保存失败 |
168
+ | 5 | 部分图片成功 |
169
+ | 130 | 用户中断;不能保证取消上游请求 |
170
+
171
+ ## 验证与发布
172
+
173
+ ```bash
174
+ pnpm check
175
+ node scripts/package-smoke.mjs
176
+ ```
177
+
178
+ 测试使用本地模拟中转站和真实 CLI 子进程,不消耗真实 API 额度。
179
+ CI 覆盖 Windows、Linux、macOS 和 Node.js 22、24,包括凭据权限及独立打包安装检查。
180
+ Skill 使用 skill-creator 校验器检查;Skills CLI 可用 `npx skills add ./skills --list` 验证发现。
181
+
182
+ 真实 Cubence 单张生成作为发布前人工验收,在用户明确要求并提供凭据来源后执行。
183
+ 自动发布使用 npm Trusted Publishing,需在 npm 配置对应仓库和 `release.yml`,并允许 GitHub Actions 创建 PR。
184
+ 提交 changeset 到 `main` 后会创建或更新版本 PR;合并版本 PR 后自动发布 npm 包和 GitHub Release。
185
+
186
+ 需求及设计依据见
187
+ [需求文档](https://github.com/bingwu-devkit/imgrelay/blob/main/docs/image-relay-requirements.md)、
188
+ [兼容性参考](https://github.com/bingwu-devkit/imgrelay/blob/main/docs/provider-compatibility-design.md)。
189
+
190
+ ## 许可证
191
+
192
+ [MIT](./LICENSE.md)。保留模板原有版权归属。