@myoldtime/opencode-codex-imagegen 0.2.0 → 1.0.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/README.md +79 -239
- package/codex.js +167 -0
- package/errors.js +24 -0
- package/google.js +79 -0
- package/images.js +235 -0
- package/index.js +100 -56
- package/package.json +15 -10
- package/parameters.js +151 -0
- package/routing.js +46 -0
- package/CHANGELOG.md +0 -21
- package/VALIDATION.md +0 -50
- package/core.mjs +0 -561
package/routing.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { connection, googleOnlyRatios } from "./parameters.js"
|
|
2
|
+
import { generate, loadInputs } from "./images.js"
|
|
3
|
+
import { ProviderFailure } from "./errors.js"
|
|
4
|
+
import { codexUnsupported } from "./codex.js"
|
|
5
|
+
import { googleUnsupported } from "./google.js"
|
|
6
|
+
|
|
7
|
+
function unsupportedReason(provider, job, inputs) {
|
|
8
|
+
if (provider === "google") return googleUnsupported(job, inputs)
|
|
9
|
+
if (job.imageSize || googleOnlyRatios.includes(job.aspect)) return "本次分辨率档位或画幅需要 Google。"
|
|
10
|
+
if (provider === "codex") return codexUnsupported(job.params, inputs.mask)
|
|
11
|
+
if (provider === "openrouter" && inputs.mask) return "OpenRouter Sunburst 不支持蒙版。"
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// The caller owns this map per session. Keep only redacted diagnostic strings,
|
|
15
|
+
// never clients, keys, request bodies, or an installation-wide "current" provider.
|
|
16
|
+
export async function route(job, disabled, active, attempts) {
|
|
17
|
+
const inputs = await loadInputs(job)
|
|
18
|
+
for (const candidate of active) {
|
|
19
|
+
const { provider, settings } = candidate
|
|
20
|
+
job.signal.throwIfAborted()
|
|
21
|
+
const entry = { provider }
|
|
22
|
+
attempts.push(entry)
|
|
23
|
+
if (disabled.has(provider)) {
|
|
24
|
+
Object.assign(entry, { status: "skipped", reason: `本会话已停用:${disabled.get(provider)}` })
|
|
25
|
+
continue
|
|
26
|
+
}
|
|
27
|
+
const unsupported = unsupportedReason(provider, job, inputs)
|
|
28
|
+
if (unsupported) {
|
|
29
|
+
Object.assign(entry, { status: "skipped", reason: unsupported })
|
|
30
|
+
continue
|
|
31
|
+
}
|
|
32
|
+
const timeout = AbortSignal.timeout(10 * 60_000)
|
|
33
|
+
try {
|
|
34
|
+
const config = provider === "codex" ? undefined : connection(provider, settings)
|
|
35
|
+
await generate({ ...job, ...inputs, signal: AbortSignal.any([job.signal, timeout]), provider, config, candidate })
|
|
36
|
+
entry.status = "succeeded"
|
|
37
|
+
return provider
|
|
38
|
+
} catch (error) {
|
|
39
|
+
job.signal.throwIfAborted()
|
|
40
|
+
Object.assign(entry, { status: "failed", reason: timeout.aborted ? "请求超时。" : error.message })
|
|
41
|
+
if (error instanceof ProviderFailure && error.disable) disabled.set(provider, entry.reason)
|
|
42
|
+
if (job.saved.length || !(error instanceof ProviderFailure) || !error.fallback) throw error
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
throw new Error("没有可完成本次请求的服务。")
|
|
46
|
+
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
## 0.2.0
|
|
4
|
-
|
|
5
|
-
- `proxy_imagegen` 可通过 `options.provider: "google"` 调用 Google Gemini Interactions API,实现文生图和多参考图编辑,默认使用 `gemini-nano-banana-2.1`。支持 `aspect_ratio`、`image_size` 以及 PNG / JPEG 输出。
|
|
6
|
-
- Google 模式支持可选的 `options.base_url`,经由自定义反向代理转发原生 Gemini Interactions 请求;不配置时直连 Google。
|
|
7
|
-
- 默认仍使用 OpenAI;Google 需要单独的 Gemini API key,不借用宿主 OpenAI 凭据,也不会在失败时切换后端。
|
|
8
|
-
|
|
9
|
-
## 0.1.0
|
|
10
|
-
|
|
11
|
-
- 首个发布版本,包名 `@myoldtime/opencode-codex-imagegen`,插件 id `opencode-codex-imagegen`,工具名 `proxy_imagegen`(不变)。历史本地版本的 id(`local.codex-proxy-imagegen`、`myoldtime.codex-proxy-imagegen`)仅存在于迁移说明中作为旧 id 出现。
|
|
12
|
-
- 双源发布:npmjs 与 GitHub Packages 使用同一个 scoped 包名,各自通过显式 `--registry` + `--@myoldtime:registry` 发布;GitHub Actions 在 Release `published` 时发布 GitHub Packages,npmjs 由本机已登录账号在确认后执行 `npm run publish:npm`。
|
|
13
|
-
- 显式 `options.base_url` + `options.key` 优先,且完全不读取宿主凭据;仅给有效的 `key` 时默认 `https://api.openai.com/v1`。**只要写了 `base_url` / `key`,空串、`null`、全空白、未解析的 `{env:...}` 一律报错**,只有两者都完全省略才走宿主账号。
|
|
14
|
-
- 未配置凭据时通过 `ctx.integration.connection.active("openai")` + `resolve(connection)` 使用 OpenCode 托管的 OpenAI 账号,每次调用重新解析,刷新由宿主负责。
|
|
15
|
-
- 支持三种登录方法的路由:`chatgpt-token-sharing` → `https://api.openai.com/v1/responses`;`chatgpt-browser` / `chatgpt-headless` → `https://chatgpt.com/backend-api/codex/responses`;未知方法明确报错。
|
|
16
|
-
- 仍只使用 Responses 托管 `image_generation` 工具(非 Images API)。
|
|
17
|
-
- 失败不重试、不换通道;错误只暴露 HTTP 状态与白名单错误码,不输出上游正文、token 或账号。
|
|
18
|
-
- 响应体/SSE 读取期间的网络错误统一归一为固定文案;超时或取消后的晚到结果在落盘前丢弃,落盘阶段取消只清理本次新建的文件。
|
|
19
|
-
- 保留模型/画质/尺寸/推理强度/优先级/超时/参考图/PNG 独占版本保存行为。
|
|
20
|
-
- 内置自动化测试全部离线;另已实际验证 API 中转、两种 legacy 登录均出图成功。新版 Sign in with ChatGPT 被上游以 `subscription_sharing_unsupported_capability` 拒绝,限制已在文档明确说明。
|
|
21
|
-
- 兼容缺失 Content-Type 的 Codex SSE 响应,支持单字节/UTF-8 分片格式检测。
|
package/VALIDATION.md
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
# 验证记录
|
|
2
|
-
|
|
3
|
-
## Google Gemini 适配(2026-11-26)
|
|
4
|
-
|
|
5
|
-
- 使用注入的 `fetch` 测试 Google Interactions REST 请求及 `model_output` 响应,覆盖文生图、多参考图编辑、权限、格式校验、不覆盖文件、失败不重试和取消/超时不写盘。原 OpenAI/Codex 测试一并回归。
|
|
6
|
-
- `npm run check`、`npm test`(45 项通过,其中新增 Google 测试 9 项)及 `npm pack --dry-run --json` 均通过。Google 自定义代理以模拟响应检查 URL 拼接、请求头、禁止重定向以及失败不回退。
|
|
7
|
-
- 后续经用户配置的代理实测一次:最小 `model` + `input` 请求返回 HTTP 200、`Content-Type: application/json`、`status: completed`,内嵌 JPEG。使用同一次响应的图片数据离线重放验证转码,得到 1376×768 的 PNG。未用真实请求验证可选尺寸参数或图生图。修复后 46 项离线测试通过。
|
|
8
|
-
|
|
9
|
-
## 0.1.0 历史验证
|
|
10
|
-
|
|
11
|
-
测试日期:2026-10-30。宿主 OpenCode 2.2.0,Node.js 24.18.0,Windows。
|
|
12
|
-
|
|
13
|
-
### 自动化测试
|
|
14
|
-
|
|
15
|
-
- `npm ci --ignore-scripts`:通过(无新增依赖,0 vulnerabilities)。
|
|
16
|
-
- `npm run check`:通过。
|
|
17
|
-
- `npm test`:36 项通过,无跳过(`test.mjs` 26 项 + `release.test.mjs` 10 项)。
|
|
18
|
-
- `npm pack --dry-run --json`:通过,`@myoldtime/opencode-codex-imagegen@0.1.0`,7 个文件(`package.json`、`index.js`、`core.mjs`、`README.md`、`VALIDATION.md`、`CHANGELOG.md`、`LICENSE`)。
|
|
19
|
-
- 包内容使用 `package.json` 的 `files` 白名单,不包含凭据、原始响应、测试图片、测试脚本、`.github` 或机器配置。
|
|
20
|
-
- 路由测试覆盖显式 API key、宿主托管 API key 和三种 OAuth 方法;另覆盖权限、凭据刷新委托、严格配置校验、错误脱敏、流式解析、取消与超时、引用图片以及文件不覆盖。
|
|
21
|
-
|
|
22
|
-
### 重命名与双源发布准备(离线)
|
|
23
|
-
|
|
24
|
-
- 本轮只做元数据与文档重命名,未重新联网生成图片:`core.mjs` 逻辑未改动。改名前后的 SHA256 均为 `D04176C047A350BD2198A56EFE024385B1DDB6E862571293010D0EDEF7EFC896`;`index.js` 仅插件 ID 从 `myoldtime.codex-proxy-imagegen` 改为 `opencode-codex-imagegen`,工具名 `proxy_imagegen` 不变。
|
|
25
|
-
- 包名在 npmjs 与 GitHub Packages 统一为 `@myoldtime/opencode-codex-imagegen`,`package.json` 与 `package-lock.json` 同名同版本(0.1.0,MIT)。
|
|
26
|
-
- `publish:npm` / `publish:github` 各自显式给出 `--registry` 与 `--@myoldtime:registry`(同一目标 URL),`publishConfig` 只保留 `access: public`,项目不含 `.npmrc`;`release.test.mjs` 断言脚本、workflow 的 registry/scope override、tag 与版本、`access`、`NODE_AUTH_TOKEN` 仅来自 `secrets.GITHUB_TOKEN`、files 白名单不含凭据与测试。
|
|
27
|
-
- GitHub Actions 只在 Release `published` 时发布 GitHub Packages;npmjs 由本机已登录账号在用户未来单独确认后执行 `npm run publish:npm`。本机 npm 登录不会传入 Actions,因此没有配置 `NPM_TOKEN`,也未做 OIDC 自动授权。
|
|
28
|
-
|
|
29
|
-
### 真实请求(历史记录,本轮未重复执行)
|
|
30
|
-
|
|
31
|
-
下表是代码与账号能力的历史验证,不属于本轮离线重命名验证;本轮未再次联网生成,也未验证真实发布。
|
|
32
|
-
|
|
33
|
-
| 通道 | 当前证据 | 范围 |
|
|
34
|
-
|---|---|---|
|
|
35
|
-
| 显式 API 配置 | 成功生成 PNG,1536×1024 | 通过既有 Responses 兼容中转,非官方 API key 直连验证 |
|
|
36
|
-
| Codex browser (legacy) | 成功生成 PNG,1536×1024,约 21 秒 | 在隔离测试插件中调用生产核心,并使用真实宿主 `connection.active/resolve`,没有手动读取或刷新凭据文件;临时会话已清理 |
|
|
37
|
-
| Sign in with ChatGPT | 上游拒绝:HTTP 400 / `subscription_sharing_unsupported_capability`,约 1.8 秒 | 用户确认准备后,经真实宿主解析此登录方式并请求官方 Responses;没有生成图片,没有重试或换通道;不是生图成功 |
|
|
38
|
-
| Codex device code (legacy) | 成功生成 PNG,1536×1024,约 23 秒 | 用户确认准备后,经真实宿主 `connection.active/resolve` 解析 device-code 登录;临时会话已清理 |
|
|
39
|
-
|
|
40
|
-
实际图片尺寸可能由上游调整,不保证与请求尺寸完全一致。验证仅针对当次账号、模型和服务状态,不承诺所有订阅与未来上游版本均可用。
|
|
41
|
-
|
|
42
|
-
legacy 验证发现真实响应可能省略 Content-Type,已修复为有界前缀格式检测,并新增单字节分片回归;另外通过保留的真实响应离线重放恢复图片,未为重放重复发起请求。
|
|
43
|
-
|
|
44
|
-
### 发布与安装
|
|
45
|
-
|
|
46
|
-
**当前状态:尚未创建远端仓库、未 push、未打 tag、未发布 Release、未运行任何发布命令,也未切换正在使用的插件。** 本节命令只有用户未来单独确认后才会使用。
|
|
47
|
-
|
|
48
|
-
- npmjs:本机 `npm whoami` 已确认为 `myoldtime`(只读检查,未登录、未读取 token);确认后执行 `npm run publish:npm`。发布前可先运行只读的 `npm view @myoldtime/opencode-codex-imagegen@0.1.0 version --registry=https://registry.npmjs.org --@myoldtime:registry=https://registry.npmjs.org` 与 `npm pack --dry-run`(查固定版本,并显式覆盖可能存在的 scope 映射)。
|
|
49
|
-
- GitHub Packages:在 <https://github.com/MyOldTime/opencode-codex-imagegen> 发布 Release(tag `v0.1.0`)后,由 [Actions](https://github.com/MyOldTime/opencode-codex-imagegen/actions) 中的 `publish.yml` 发布,并在同一 workflow 里做版本校验。实际发布状态以 Actions 与 [Release](https://github.com/MyOldTime/opencode-codex-imagegen/releases/tag/v0.1.0) 为准。
|
|
50
|
-
- 安装应使用固定版本,并确认宿主显示插件来源为 package 而非旧本地目录。README 中在线安装说明均标注为"发布后可用"。
|