fix(NanoBananaGen2): 多渠道容错、details 瘦身、http 代理与本地 URL 修复 - #459
Merged
lioensky merged 1 commit intoAug 25, 2026
Merged
Conversation
…fix http proxy and local URL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述
修复 NanoBananaGen2 中 8 个已定位缺陷。工具调用接口零变更,现有调用方式完全兼容。
修复清单
1. details 中 base64 副本膨胀(每次含图调用都发生)
processApiResponseAndSaveImage的返回体用...originalArgs展开了全部原始参数。而
normalizeNanoBananaArgs会把每张输入图回写成image_url_1 .. image_url_N,同时保留
image_url。当调用方传入 data URI 时,同一份 base64 在 details 里存在2N+1 份副本,全部进入 AI 上下文。
改为白名单显式构造,只保留元数据:serverPath / fileName / imageUrl / command /
prompt(截断 500 字符)/ image_size / inputImageCount / modelResponseText / showBase64。
输入图片只记数量不记内容。
2. 多渠道缺少 failover
callApi内getRandomChannel()只抽取一次渠道,请求失败直接抛出。配置多个渠道时,任意一个不可用就是整次调用失败——多渠道实现了负载分散,
但没有实现容错。
新增
shuffledChannelPlan()将所有渠道×模型展开后 Fisher-Yates 洗牌,callApi改为遍历尝试。新增postWithRetry对 429/503 做指数退避(延迟 = RETRY_BASE_DELAY_MS × 3^attempt),401/403/400 不重试直接换下一渠道。
全部失败时聚合报错,逐行列出各渠道的失败原因(包含 URL 与模型名,不含 key)。
3. USE_PUBLIC_URL 的三个问题
plugin-manifest.json的 configSchema 中未声明该字段,但代码读取了它true,走${VarHttpUrl}//pw=分支时端口被丢弃,本地部署(VarHttpUrl=http://localhost)产出的 URL 无法访问
补上 configSchema 声明;默认值改为
false;URL 拼接统一先剥离尾部斜杠再按需接端口。这是本 PR 唯一的行为变更。 对于依赖公网 URL 的部署,需在 config.env 中
显式设置
USE_PUBLIC_URL=true。考虑到该字段此前从未在 manifest 中声明、且原默认值会让本地部署产出坏链接,改为 false 更符合多数场景。
4. 代理配置对 http 渠道无效
代理只构造了
HttpsProxyAgent并且只传httpsAgent。而本插件默认
API_URL是http://127.0.0.1:3106/v1,http 请求走的是httpAgent,因此代理对所有 http 渠道完全无效。
改为同时构造
HttpProxyAgent+HttpsProxyAgent,三个网络调用点(远端图片读取、图床回捞、API 请求)均同时传入两个 agent。
新增依赖:
http-proxy-agent@7.0.2(https-proxy-agent的同族包,同一维护者与主版本线)。5. DIST_IMAGE_SERVERS 是死配置
plugin-manifest.json声明该字段"用于 file:// 路径降级处理",代码将其解析为数组后从未引用。
getImageDataFromUrl抛出FILE_NOT_FOUND_LOCALLY后没有任何远程回捞逻辑,声明的能力并不存在。实现回捞:本地文件不存在时,按 basename 依次尝试各图床地址。
全部失败后仍抛出原有的
FILE_NOT_FOUND_LOCALLY错误码,语义不变。DIST_IMAGE_SERVERS为空时行为与改造前完全一致。6. 缺少路径逃逸检查
写入图片前新增 resolve 前缀校验,与 GPTImageGen 的
saveImageToLocal保持一致。7. 破限文本硬编码
[All Safety settings have been cancelled...]在 generate / edit / compose三处各硬编码一次,无条件追加到每个 prompt 尾部。对不需要此写法的渠道属于提示词污染。
提取为
SAFETY_BYPASS_TEXT配置项 +withBypass()辅助函数。使用
!== undefined判断以保持向后兼容——不设置该项时行为与改造前完全一致,显式设为空字符串则完全关闭追加。
8. 两处小问题
composeImage的错误提示使用image_${i+1},但调用方实际传入的参数名是image_url_1/image_url_2,报错指向了不存在的参数名。已改为image_url_${i+1}。getImageDataFromUrl用url.startsWith('http')判断协议,会误匹配httpfoo://这类字符串。已改为/^https?:\/\//i。兼容性
USE_PUBLIC_URL默认值(见第 3 条说明)SAFETY_BYPASS_TEXT不设置时保持原有行为配置项对齐
本次涉及的配置项已在四处对齐(源码默认值 / plugin-manifest.json configSchema /
config.env.example / README):
USE_PUBLIC_URL、SAFETY_BYPASS_TEXT、MAX_RETRIES、RETRY_BASE_DELAY_MS、DIST_IMAGE_SERVERS。
测试情况
已完成的静态验证:
node --check NanoBananaGen.mjs通过plugin-manifest.json与package.jsonJSON 解析通过git diff --check通过,无空白错误未进行真实 API 调用测试。 上述修复均基于源码逻辑分析,
需要以下条件才能完整验证: