@wacry/codeks-bridge 0.0.20 → 0.0.22
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 +1 -1
- package/catalog/README.md +5 -1
- package/catalog/gemini-3.8-flash.json +183 -0
- package/catalog/gemini-4-argon.json +183 -0
- package/dist/auth.js +1 -1
- package/dist/backends/gemini.d.ts +8 -0
- package/dist/backends/gemini.js +380 -0
- package/dist/errors.js +1 -1
- package/dist/headers.js +1 -1
- package/dist/inspect/capture.js +17 -3
- package/dist/model-catalog.d.ts +1 -1
- package/dist/model-catalog.js +1 -0
- package/dist/profiles.js +3 -0
- package/dist/server.js +2 -1
- package/dist/types.d.ts +2 -2
- package/docs/backends-gemini.md +78 -0
- package/docs/config.md +5 -4
- package/docs/design.md +11 -3
- package/docs/inspect.md +3 -1
- package/docs/reasoning.md +3 -2
- package/docs/testing.md +8 -0
- package/docs/tools.md +10 -8
- package/examples/config.json +9 -0
- package/package.json +2 -2
- package/ui/events.js +59 -6
- package/ui/latency.js +6 -0
package/docs/design.md
CHANGED
|
@@ -10,9 +10,11 @@ flowchart LR
|
|
|
10
10
|
R --> G[GPT Responses]
|
|
11
11
|
R --> A[Claude Messages]
|
|
12
12
|
R --> D[DeepSeek Chat]
|
|
13
|
+
R --> N[Gemini GenerateContent]
|
|
13
14
|
G --> W[Responses writer]
|
|
14
15
|
A --> W
|
|
15
16
|
D --> W
|
|
17
|
+
N --> W
|
|
16
18
|
W --> C
|
|
17
19
|
```
|
|
18
20
|
|
|
@@ -22,7 +24,7 @@ flowchart LR
|
|
|
22
24
|
|
|
23
25
|
优先匹配最新 Codex 的 GPT 默认行为,以 OpenAI 订阅、AWS 和 Azure 的使用场景为基准。当前模型条目使用 Responses Lite,现代条目保留 Code Mode Only 和多代理字段;GPT-5.5 显式启用 Lite,其余工具与多代理元数据仍跟随源条目。目录固定到已审阅的来源版本,不随用户本机二进制或订阅账号变化。
|
|
24
26
|
|
|
25
|
-
Lite 仍调用 `/responses` 并返回 Responses SSE。完整工具 schema 位于历史中的 `additional_tools` 项,普通函数和 custom 工具归入默认 `functions` namespace。GPT 路径保留这些声明的位置、顺序、schema 和 grammar,并发送 `x-openai-internal-codex-responses-lite: true`。Claude 与
|
|
27
|
+
Lite 仍调用 `/responses` 并返回 Responses SSE。完整工具 schema 位于历史中的 `additional_tools` 项,普通函数和 custom 工具归入默认 `functions` namespace。GPT 路径保留这些声明的位置、顺序、schema 和 grammar,并发送 `x-openai-internal-codex-responses-lite: true`。Claude、DeepSeek 与 Gemini 按历史顺序将各批定义合并到顶部,同 namespace 与工具名只保留最新定义,未变的其他成员保留。声明不会变成 user reminder。中途提醒保留所在对话位置;若插在一次完整的工具交换内,则移至该批结果之后,以满足目标协议的配对要求。
|
|
26
28
|
|
|
27
29
|
已核对 Codex `0.163.0`:Lite 设置 `reasoning.context: "all_turns"` 和 `parallel_tool_calls: false`。bridge 保留客户端传入值,原生 options 仍可按配置覆盖普通参数。reasoning 的来源筛选与服务端 context 语义是两件事:前者决定发送哪些载荷,后者决定 GPT 如何使用它们。原生压缩与随后的复述保留源 Lite 工具声明及 transport 标记。
|
|
28
30
|
|
|
@@ -30,7 +32,7 @@ Lite 仍调用 `/responses` 并返回 Responses SSE。完整工具 schema 位于
|
|
|
30
32
|
|
|
31
33
|
## 有限目录与显式精调
|
|
32
34
|
|
|
33
|
-
项目只支持明确列出的模型。`catalog/` 保存每个模型的完整条目及来源;GPT 分别使用 Codex 源码中各自的版本,保留提示词、默认 effort、摘要、窗口和工具元数据的差异,所有 GPT 统一使用 `shell_type: "unified_exec"`;旧 shell 名称的等价转换、GPT-5.5 的 Lite 调整及用户指定的窗口调整均记录在各条目的 `adjustments`。源码尚未收录的 GPT-Reserve 使用取得并审阅的订阅目录快照,记录端点、取得日期与客户端版本;具体来源与公开信息处理见[模型目录](../catalog/README.md)。Claude 与
|
|
35
|
+
项目只支持明确列出的模型。`catalog/` 保存每个模型的完整条目及来源;GPT 分别使用 Codex 源码中各自的版本,保留提示词、默认 effort、摘要、窗口和工具元数据的差异,所有 GPT 统一使用 `shell_type: "unified_exec"`;旧 shell 名称的等价转换、GPT-5.5 的 Lite 调整及用户指定的窗口调整均记录在各条目的 `adjustments`。源码尚未收录的 GPT-Reserve 使用取得并审阅的订阅目录快照,记录端点、取得日期与客户端版本;具体来源与公开信息处理见[模型目录](../catalog/README.md)。Claude、DeepSeek 与 Gemini 从 GPT-6.1 Sol 模板开始,只替换底层模型身份(如 `You are Codex, an agent based on Claude.`),保留 Codex 代理角色及 `As Codex` 人格说明;参数和确有差异的能力逐项精调,记录在条目的 `adjustments`。摘要默认值继续使用模板的 `none`,是否展示由客户端配置决定,不为第三方模型强制打开。
|
|
34
36
|
|
|
35
37
|
导入脚本只生成独立候选文件,供人或 Agent 对比审阅。运行时使用已提交的完整条目,不自动导入、不猜测未知模型,也不从 ChatGPT 订阅获取目录。这样更新仍有工具辅助,同时提示词和能力变化可审查、可追踪。来源及更新步骤见[模型目录](../catalog/README.md)。
|
|
36
38
|
|
|
@@ -44,7 +46,13 @@ Lite 仍调用 `/responses` 并返回 Responses SSE。完整工具 schema 位于
|
|
|
44
46
|
|
|
45
47
|
`GET /v1/models` 提供 Codex 原生目录响应,CLI 默认生成显式 `model_catalog_url`;也可导出静态文件。两种目录都只包含 `expose` 未关闭的别名;`visibility: "hide"` 保留完整条目但在客户端选择器中隐藏,默认 `"list"`。目录省略与选择器隐藏分开,让内部压缩预设和仍需客户端元数据的 Memory、已有会话各取所需;两者都不改变调用权限或状态身份。服务启动时展开配置,目录与普通响应通过 ETag 关联,客户端看到新版本后刷新。目录只包含客户端需要的公开模型元数据,不包含连接或凭据配置。
|
|
46
48
|
|
|
47
|
-
底层 Chat 负责消息、工具、图片和 SSE;DeepSeek 方言负责 thinking 参数、reasoning 字段、结构化输出转换和 usage。新增方言时复用稳定的协议部分,把差异留在对应 adapter。协议相同的模型版本可共用 adapter
|
|
49
|
+
底层 Chat 负责消息、工具、图片和 SSE;DeepSeek 方言负责 thinking 参数、reasoning 字段、结构化输出转换和 usage。新增方言时复用稳定的协议部分,把差异留在对应 adapter。协议相同的模型版本可共用 adapter,参数差异先在新的目录条目中表达;真正改变载荷结构时再增加转换代码和格式版本。当前实现四类 adapter,不为尚未接入的模型维护空接口或版本矩阵。
|
|
50
|
+
|
|
51
|
+
## Gemini 的原生状态放在历史里
|
|
52
|
+
|
|
53
|
+
Gemini 使用 `streamGenerateContent`,不走 Chat 兼容层。`thoughtSignature` 绑定原始 part,工具和正文的可见输出仍由 Responses 交付,同源回放时再由 carrier 恢复对应的完整 part。这样签名可以随 codeks 会话、resume 和 fork 一起保存,不依赖运行中的 bridge 进程。
|
|
54
|
+
|
|
55
|
+
对比参考实现后保留这个选择:[Magpie 的磁盘签名存储](https://github.com/yetone/magpie/blob/e056779a67d2024a09aa25edad8a4373931a5b64/internal/gateway/gemini_sigstore.go)依赖本地文件及 call ID 引用,[CC Switch 的 session shadow](https://github.com/farion1231/cc-switch/blob/ee8ee25ebc63faa877e779f0831e29cf2b369604/src-tauri/src/proxy/providers/gemini_shadow.rs)依赖有限容量的内存会话。bridge 已有自包含的 `cxbr1:` 格式,无需增加另一份恢复状态,也不把签名塞进可能受长度限制的调用 ID。原生 JSON Schema 通道可以保留工具约束;不复制参考实现中的 schema 猜测、签名重排或缺少终止时的成功回退。协议细节和真实验证范围见 [Gemini adapter](backends-gemini.md)。
|
|
48
56
|
|
|
49
57
|
## 订阅鉴权复用文件登录
|
|
50
58
|
|
package/docs/inspect.md
CHANGED
|
@@ -55,6 +55,8 @@ codeks-bridge serve --config /absolute/path/bridge.json --capture
|
|
|
55
55
|
|
|
56
56
|
大内容只在显示时折叠,记录本身完整。长字符串显示开头和结尾,中间注明省略的字符数,可以展开全部、复制或下载;`cxbr1:` 与 `cxbc1:` 载荷可以直接解码。很长的列表分批显示,可以继续加载。Responses Lite 的终止事件可能省略完整 `output`;结构视图会用之前的 `response.output_item.done` 还原输出,原始事件保持不变。
|
|
57
57
|
|
|
58
|
+
Gemini 原生流按 candidate 合成结构视图,只拼接相邻的无签名文字,保留 `thoughtSignature` 所在 part、函数调用和上游终止原因。`usageMetadata` 使用最后一次报告,输出 token 为 `candidatesTokenCount + thoughtsTokenCount`,缓存取 `cachedContentTokenCount`;不把多次累计报告相加。thought 文字、正文与函数调用分别计入延迟,空文字和签名不计入。结构合成不会补造成功状态,原始事件仍可逐条查看。
|
|
59
|
+
|
|
58
60
|
模型请求的列表和详情顶部 token 用量取自写回 codeks 的响应,只代表该次 main、summary 或 native 调用。handoff 的独立 usage 可在它的上游响应中查看:SSE 事件、结构或 JSON 视图保留原始字段,不累加进客户端用量。缓存命中不产生新的 handoff 调用,也不重复展示为本次消耗。搜索与图片请求保留上游原始响应及其 usage;图片用量只属于本次独立调用,不累加到后续推理。检查器没有跨调用的计费总额;上游没有报告的字段不能按零消耗理解。
|
|
59
61
|
|
|
60
62
|
“概要”给出实际执行模型的路由配置、每个调用的时间线和上游调用表;模型推理请求的客户端模型字段仍保留用户请求的工作别名;图片请求显示客户端指定的图片模型。“标注”列出全部回放决定,点击可定位到对应项。“对比”选择任意两次交换的任意一段做结构比较,常用的是和同一线程上一轮的客户端请求或上游请求比较;数组按类型和角色对齐,新增、删除的项单独标出。
|
|
@@ -75,7 +77,7 @@ codeks-bridge serve --config /absolute/path/bridge.json --capture
|
|
|
75
77
|
|
|
76
78
|
正文完整保存,不做字段白名单,也不在服务端截断。codeks 或上游新增的字段原样出现,页面只在显示时折叠。
|
|
77
79
|
|
|
78
|
-
|
|
80
|
+
凭据类 header 与上游 URL 查询值会脱敏。名称按 `-`/`_` 分段后含 `auth`、`authorization`、`token`、`secret`、`password`、`passwd`、`cookie`、`key`、`apikey`、`credential(s)` 或 `signature` 的值替换为 `[redacted: N chars, sha256 xxxxxxxx]`,覆盖 `x-goog-api-key` 和 `?key=`;普通查询参数如 `alt=sse` 保留。长度和哈希前缀可以用来判断两次请求是否用了同一个凭据。脱敏只影响捕获记录,实际请求不变;正文不脱敏。
|
|
79
81
|
|
|
80
82
|
几处需要注意的边界:
|
|
81
83
|
|
package/docs/reasoning.md
CHANGED
|
@@ -4,9 +4,9 @@ bridge 能识别的 reasoning 默认只恢复给产生它的目标,配置可
|
|
|
4
4
|
|
|
5
5
|
## 显示与推理分开
|
|
6
6
|
|
|
7
|
-
目录的 `default_reasoning_summary`、客户端的 `model_reasoning_summary` 和请求的 `reasoning.summary` 控制可见摘要,不决定是否进行推理。Claude / DeepSeek 沿用 GPT-6.1 Sol 的摘要默认值 `none`;在 codeks 配置 `model_reasoning_summary = "auto"` 可打开显示,也可使用 `concise` 或 `detailed`。Codex `0.163.0` 在 `codex-rs/core/src/client.rs` 的 `build_reasoning` 中将有效配置 `none` 表达为省略请求的 summary
|
|
7
|
+
目录的 `default_reasoning_summary`、客户端的 `model_reasoning_summary` 和请求的 `reasoning.summary` 控制可见摘要,不决定是否进行推理。Claude / DeepSeek / Gemini 沿用 GPT-6.1 Sol 的摘要默认值 `none`;在 codeks 配置 `model_reasoning_summary = "auto"` 可打开显示,也可使用 `concise` 或 `detailed`。Codex `0.163.0` 在 `codex-rs/core/src/client.rs` 的 `build_reasoning` 中将有效配置 `none` 表达为省略请求的 summary 字段,因此这些 adapter 对缺省和 `none` 都不输出可见摘要,仍保存完整原生载荷,并按来源策略回放。GPT 直接保留原生参数和上游摘要事件,由上游响应请求中的显示选择,不在桥接层再次改写摘要。
|
|
8
8
|
|
|
9
|
-
启用显示时,Claude 请求 summarized thinking,DeepSeek 展示上游 reasoning
|
|
9
|
+
启用显示时,Claude 请求 summarized thinking,DeepSeek 展示上游 reasoning 文本,Gemini 请求原生 thought 摘要,不另外调用模型生成摘要。`auto`、`concise` 和 `detailed` 在这些 adapter 中都表示请求可见内容,不承诺复现 GPT 的摘要长度差异。隐藏摘要也不意味着丢弃签名、密文或明文 reasoning;这些数据仍由 carrier 持久化。
|
|
10
10
|
|
|
11
11
|
## 保存格式
|
|
12
12
|
|
|
@@ -36,6 +36,7 @@ JSON 的结构如下,示例指纹为占位值:
|
|
|
36
36
|
| `gpt-responses` | `responses.reasoning.v1` | 上游原始 `encrypted_content` 字符串 |
|
|
37
37
|
| `claude-messages` | `anthropic.thinking.v1` | 完整 `thinking` 或 `redacted_thinking` block,包含签名或隐藏数据 |
|
|
38
38
|
| `deepseek-chat` | `reasoning.text.v1` | 明文 reasoning 字符串 |
|
|
39
|
+
| `gemini-native` | `gemini.parts.v1` | 原生 parts 及其可见输出关联,保留每个 `thoughtSignature` 所在 part |
|
|
39
40
|
|
|
40
41
|
一个 carrier 对应一项 reasoning;格式可以保存字符串或结构化数据,不限于可见文字。外层只是编码,不是加密。GPT 密文本身不变;Claude 可见 thinking 和 DeepSeek 文本仍可解码。
|
|
41
42
|
|
package/docs/testing.md
CHANGED
|
@@ -40,6 +40,14 @@ Claude 续接边界的回归同时检查生成和下一轮回放:首块 thinki
|
|
|
40
40
|
|
|
41
41
|
`test/delegated-compaction-e2e.test.ts` 通过 bridge 的真实 HTTP 入口连接本地假上游,覆盖 GPT 原生续聊 → Claude 按需复述 → Claude 委托 GPT 再压缩 → Claude 复述新检查点 → GPT 恢复新检查点。另检查 native 失败不交付部分检查点、handoff 失败不调用工作模型、工作模型失败后跨服务重启复用成功缓存,以及 inspector 的独立 handoff usage 不进入客户端响应。它不启动 codeks,也不调用真实模型;委托压缩的质量与成本不由这些测试推断。
|
|
42
42
|
|
|
43
|
+
## Gemini 原生接口验证
|
|
44
|
+
|
|
45
|
+
`test/gemini.test.ts` 覆盖原生 parts 和签名绑定、并行同名调用、别名错误反馈、跨来源筛选、原位提醒、图片、根引用 schema、结构化输出及失败不释放工具。中间 `usageMetadata` 可以仅有非计数字段;最终快照在终止后验证,不逐 chunk 累加。`test/gemini-e2e.test.ts` 用真实客户端检查工具执行、载体持久化与跨进程 resume,摘要开关不影响签名保存。
|
|
46
|
+
|
|
47
|
+
2026-10-27 通过 Vertex AI 路由对 Gemini 3.8 Flash / 4 Argon 做原生协议与真实 bridge HTTP 验证。原生 18 个请求中,15 个成功,3 个按预期拒绝无签名当前工具轮次或末尾 model;bridge 的 9 个成功请求覆盖两个模型的工具往返、签名回放、新用户轮次、图片与 JSON Schema,以及 Flash 的标准文字压缩。另一次上游 HTTP 502 原样报错;测试脚本后来重跑成功,bridge 没有自动重试。测试也发现并修复了中间 usage 缺计数导致过早拒绝的问题。
|
|
48
|
+
|
|
49
|
+
这些结果不是 AI Developer API 直连、所有区域或跨模型签名兼容的证明;没有评估压缩质量或缓存命中率。公开测试使用合成签名和内容,真实端点、鉴权及原始响应保存在仓库外。
|
|
50
|
+
|
|
43
51
|
## 使用真实 codeks 二进制
|
|
44
52
|
|
|
45
53
|
可选集成测试启动已经安装的 codeks,并让它通过桥接器访问本地假上游。指定要验证的二进制即可,测试不会下载或编译 codeks:
|
package/docs/tools.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# 工具转换
|
|
2
2
|
|
|
3
|
-
客户端负责执行工具,bridge 只转换定义、调用和结果。Responses 后端保留原生定义;Messages 与
|
|
3
|
+
客户端负责执行工具,bridge 只转换定义、调用和结果。Responses 后端保留原生定义;Messages、Chat 与 Gemini 后端只向模型提供普通函数。
|
|
4
4
|
|
|
5
5
|
## Lite 工具声明
|
|
6
6
|
|
|
7
|
-
客户端默认把完整工具 schema 放在 `input[].additional_tools`。GPT 保留原始声明项。Claude 与
|
|
7
|
+
客户端默认把完整工具 schema 放在 `input[].additional_tools`。GPT 保留原始声明项。Claude、DeepSeek 与 Gemini 在转换消息前提取声明,与顶层 `tools` 按历史顺序合并,最终只向上游发送一张顶层工具表。声明不会变成普通 reminder,客户端保存的历史不变。
|
|
8
8
|
|
|
9
9
|
增量声明只包含新增或变更的成员,按 namespace 与工具名覆盖旧定义,保留未变的其他成员和已分配的上游名字。每个工具身份最终只有一份定义;反复切换模型产生的同名版本也只保留最后一份。工具移除的 developer 通知保留原位置,不从提示词文字推断删工具。codeks 将默认 `functions` namespace、空 namespace 和省略 namespace 视为同一身份,因此历史调用和显式工具选择均按此规则查找;返回调用保留声明中的原 namespace。
|
|
10
10
|
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
|
|
23
23
|
普通函数保留原名。namespace 中的工具使用 `namespace__name`;namespace 已以 `_` 结尾时直接拼接名字。名字规范化为字母、数字、`_` 和 `-`。只有两个不同工具的规范化结果实际冲突时,才为后来的名字加 `_2`、`_3` 等后缀。返回调用通过该请求的映射恢复原 name/namespace。
|
|
24
24
|
|
|
25
|
-
Messages/Chat 返回的调用还接受完整的 `namespace.name` 和唯一的原始短名。例如 `functions__exec`、`functions.exec`、`exec` 都可定位同一个工具;`agents`、`clock` 及其他 namespace 使用相同规则。省略 namespace 的默认工具也接受 `functions.name` 和 `functions__name`。精确声明名优先;其他别名只有唯一对应工具时才成功,不猜后缀或拼写。exec 内的 JavaScript 原样传递,其中 `tools.*` 的解析仍由客户端负责。
|
|
25
|
+
Messages/Chat/Gemini 返回的调用还接受完整的 `namespace.name` 和唯一的原始短名。例如 `functions__exec`、`functions.exec`、`exec` 都可定位同一个工具;`agents`、`clock` 及其他 namespace 使用相同规则。省略 namespace 的默认工具也接受 `functions.name` 和 `functions__name`。精确声明名优先;其他别名只有唯一对应工具时才成功,不猜后缀或拼写。exec 内的 JavaScript 原样传递,其中 `tools.*` 的解析仍由客户端负责。
|
|
26
26
|
|
|
27
27
|
这一选择来自实际模型会省略声明名前缀,而提示词仍用 `functions.exec` 等原始身份。保留声明、增加确定性别名,可以修复调用而不重写工具表和 Claude 的签名前缀。GPT 返回的调用保留原生工具协议,不做这种别名匹配;切换到 GPT 时,来自其他 adapter 的历史载体仍需转换为 Responses 可接受的表示。
|
|
28
28
|
|
|
@@ -34,11 +34,11 @@ Messages/Chat 返回的调用还接受完整的 `namespace.name` 和唯一的原
|
|
|
34
34
|
|
|
35
35
|
Responses 的 `call_id` 最长 64 字符,`cxbt1_` 载体可能超过这个限制。GPT 出站时,对超过 64 字符的工具 ID(包括载体和其他上游的原始 ID),使用完整客户端 ID 的 SHA-256 生成固定 48 字符的 `call_`+base64url 摘要;function/custom 调用及对应结果使用同一映射。64 字符以内的 ID(包括短载体)保留原值,减少对已被 GPT 接受的历史前缀的改动;无 ID 的主动通知不生成 ID。映射不依赖调用位置、模型别名或内存状态,因此恢复会话、重试及后续 turn 都保持一致。
|
|
36
36
|
|
|
37
|
-
不直接用载体内的原始 ID,是因为它本身可能超长,两个不同载体也可能包含同一个原始 ID;不直接截断或去除空白,以免合并不同调用。GPT 历史保留客户端已确定的工具类型、name、namespace、参数及正常结果,失败结果使用载体保存的原诊断。转换仅作用于请求副本:旧会话无需迁移,切回 Messages/Chat 仍能恢复原始调用。普通请求、原生压缩、文字压缩和 handoff 共用这条出站路径。
|
|
37
|
+
不直接用载体内的原始 ID,是因为它本身可能超长,两个不同载体也可能包含同一个原始 ID;不直接截断或去除空白,以免合并不同调用。GPT 历史保留客户端已确定的工具类型、name、namespace、参数及正常结果,失败结果使用载体保存的原诊断。转换仅作用于请求副本:旧会话无需迁移,切回 Messages/Chat/Gemini 仍能恢复原始调用。普通请求、原生压缩、文字压缩和 handoff 共用这条出站路径。
|
|
38
38
|
|
|
39
39
|
这种无状态的目标协议边界处理也见于 [Magpie 的 `BoundCallID`](https://github.com/yetone/magpie/blob/11c3fbb197f17403183bdae424327aa0de7f0558/internal/provider/codex_request.go#L368)。这里额外保留 bridge 的载体诊断和规范化工具身份。回归覆盖真实 codeks 的 DeepSeek/Claude → GPT → 原模型切换;另用合成历史实测 GPT‑6‑Luna / medium,280、73、90 字符 ID 转换后均为 48 字符,未声明的失败工具身份及诊断可正常回放。该实测验证协议接受性,不评估模型质量。
|
|
40
40
|
|
|
41
|
-
共享转换层将 Messages/Chat 工具名统一限制为 64 字符,沿用 Chat 端点的较小限制,不为不同后端维护两套命名规则;这不表示所有端点的原生上限都是 64。超长名称保留 55 字符可读前缀,加 `_` 与 8 位摘要,以区别同前缀工具。正常长度不加 hash。历史名称根据当前工具集映射,因此同一次工具调用的名称不依赖模型临时起名。
|
|
41
|
+
共享转换层将 Messages/Chat/Gemini 工具名统一限制为 64 字符,沿用 Chat 端点的较小限制,不为不同后端维护两套命名规则;这不表示所有端点的原生上限都是 64。超长名称保留 55 字符可读前缀,加 `_` 与 8 位摘要,以区别同前缀工具。正常长度不加 hash。历史名称根据当前工具集映射,因此同一次工具调用的名称不依赖模型临时起名。
|
|
42
42
|
|
|
43
43
|
## 自由文本与语法
|
|
44
44
|
|
|
@@ -48,7 +48,7 @@ Responses custom tool 转成只有一个必填 `input: string` 字段的函数
|
|
|
48
48
|
- Regex 定义原样写进 description,要求 `input` 匹配。
|
|
49
49
|
- 不给特定编辑或执行工具追加私有提示词,不修改其原描述。
|
|
50
50
|
|
|
51
|
-
Messages/Chat 没有 Responses 的服务端语法约束能力,因此这是模型遵循的说明,不是同等的 constrained decoding。函数参数的 JSON 外壳仍会检查;错误、不完整的工具参数不会交给客户端执行。
|
|
51
|
+
Messages/Chat/Gemini 没有 Responses 的服务端语法约束能力,因此这是模型遵循的说明,不是同等的 constrained decoding。函数参数的 JSON 外壳仍会检查;错误、不完整的工具参数不会交给客户端执行。
|
|
52
52
|
|
|
53
53
|
## 明文与多代理
|
|
54
54
|
|
|
@@ -58,14 +58,16 @@ Messages 对不符合端点格式的 call ID 采用确定性映射,并添加
|
|
|
58
58
|
|
|
59
59
|
根 schema 的 `$ref`、`$defs`、`allOf`、`anyOf`、`oneOf` 及其他约束均保留;缺少根 `type` 时补为 `object`,已有类型不覆盖,由上游判断是否支持。codeks 可以发送没有根 `type` 的引用或组合 schema,不能因此把参数清空。未提供参数 schema 时使用空对象定义;显式提供非对象 schema 值则报错,不在 bridge 内解析引用或删减约束。
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
Messages/Chat 的普通函数显式给出的 `strict: true` 或 `strict: false` 原样保留:Messages 放在工具定义顶层,Chat 放在 `function` 内;省略时不添加默认值。Lite 同名更新替换完整定义,因此新定义省略 `strict` 时也不继承旧值。custom 工具的 JSON 外壳不因此自动启用 strict。
|
|
62
62
|
|
|
63
63
|
[Claude strict tool use](https://platform.claude.com/docs/en/agents-and-tools/tool-use/strict-tool-use) 与 [DeepSeek strict mode](https://api-docs.deepseek.com/guides/tool_calls/#strict-mode-beta) 各有支持的 schema 范围;DeepSeek 官方文档还要求 beta 端点及所有函数都设为 `strict: true`。bridge 只转换调用方明确提供的字段,不切换端点、不改其他工具或删减 schema 来满足 strict。需要该能力时由用户配置支持的端点,上游不接受则保留错误。
|
|
64
64
|
|
|
65
|
-
codeks V2 多代理工具的 task/message 是明文,历史中的 `agent_message` 对 Messages/Chat 转成 user 消息,保留 author、recipient 和内容顺序。它不会成为模型 reasoning。不能解密的工具或 agent message 会明确报错。
|
|
65
|
+
codeks V2 多代理工具的 task/message 是明文,历史中的 `agent_message` 对 Messages/Chat/Gemini 转成 user 消息,保留 author、recipient 和内容顺序。它不会成为模型 reasoning。不能解密的工具或 agent message 会明确报错。
|
|
66
66
|
|
|
67
67
|
## 结果与范围
|
|
68
68
|
|
|
69
|
+
Gemini 的签名 part、并行结果顺序和工具结果图片遵循[原生接口规则](backends-gemini.md),不把签名放入工具 ID。
|
|
70
|
+
|
|
69
71
|
文本结果按对应 API 的 tool result 形式传递。Messages 可以把图片放进 `tool_result`;Chat 的工具结果只放文本,图片在同组所有工具结果之后组成 user 消息,并标注来源 call ID,避免打断并行调用的结果序列。
|
|
70
72
|
|
|
71
73
|
Responses 允许主动工具通知和一次调用的多次输出,而 Messages/Chat 要求明确配对的调用与结果。转换只作用于当前非 GPT 请求副本:
|
package/examples/config.json
CHANGED
|
@@ -13,6 +13,10 @@
|
|
|
13
13
|
"deepseek": {
|
|
14
14
|
"base_url": "https://api.deepseek.com",
|
|
15
15
|
"api_key_env": "DEEPSEEK_API_KEY"
|
|
16
|
+
},
|
|
17
|
+
"google": {
|
|
18
|
+
"base_url": "https://generativelanguage.googleapis.com/v1beta",
|
|
19
|
+
"api_key_env": "GEMINI_API_KEY"
|
|
16
20
|
}
|
|
17
21
|
},
|
|
18
22
|
"models": {
|
|
@@ -30,6 +34,11 @@
|
|
|
30
34
|
"upstream": "deepseek",
|
|
31
35
|
"model": "deepseek-flash",
|
|
32
36
|
"catalog": "deepseek-flash"
|
|
37
|
+
},
|
|
38
|
+
"gemini": {
|
|
39
|
+
"upstream": "google",
|
|
40
|
+
"model": "gemini-3.8-flash",
|
|
41
|
+
"catalog": "gemini-3.8-flash"
|
|
33
42
|
}
|
|
34
43
|
}
|
|
35
44
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wacry/codeks-bridge",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "Configurable local Responses API bridge for codeks with GPT, Claude Messages,
|
|
3
|
+
"version": "0.0.22",
|
|
4
|
+
"description": "Configurable local Responses API bridge for codeks with GPT, Claude Messages, DeepSeek Chat, and native Gemini adapters.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "David Zhang",
|
|
7
7
|
"repository": {
|
package/ui/events.js
CHANGED
|
@@ -46,7 +46,7 @@ export function inputTransformationReports(resp) {
|
|
|
46
46
|
return reports;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
/** Returns {key, text, label} for streaming
|
|
49
|
+
/** Returns {key, text, label} for streaming text deltas. */
|
|
50
50
|
function deltaOf(ev) {
|
|
51
51
|
const j = ev.json;
|
|
52
52
|
if (!j || typeof j !== 'object') return null;
|
|
@@ -72,6 +72,14 @@ function deltaOf(ev) {
|
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
+
if (j.candidates?.length === 1 && !j.candidates[0].finishReason) {
|
|
76
|
+
const candidate = j.candidates[0];
|
|
77
|
+
const parts = candidate.content?.parts;
|
|
78
|
+
if (parts?.length === 1 && plainGeminiText(parts[0])) {
|
|
79
|
+
const part = parts[0];
|
|
80
|
+
return { key: `gemini|${candidate.index ?? 0}|${part.thought === true}`, text: part.text, label: part.thought === true ? 'thought' : 'text' };
|
|
81
|
+
}
|
|
82
|
+
}
|
|
75
83
|
return null;
|
|
76
84
|
}
|
|
77
85
|
|
|
@@ -80,7 +88,7 @@ function eventType(ev) {
|
|
|
80
88
|
return ev.event ?? ev.json?.type ?? (ev.json?.object || (ev.data === '[DONE]' ? '[DONE]' : '(data)'));
|
|
81
89
|
}
|
|
82
90
|
|
|
83
|
-
/** One-line description of an event, picking common fields
|
|
91
|
+
/** One-line description of an event, picking common protocol fields. */
|
|
84
92
|
function describe(ev) {
|
|
85
93
|
const j = ev.json;
|
|
86
94
|
if (j === undefined) return oneLine(ev.data, 160);
|
|
@@ -113,6 +121,15 @@ function describe(ev) {
|
|
|
113
121
|
if (j.message && typeof j.message === 'object') out.push([j.message.model, j.message.usage && usageText(j.message.usage)].filter(Boolean).join(' '));
|
|
114
122
|
if (j.delta && typeof j.delta === 'object' && !Array.isArray(j.delta) && j.type === 'message_delta') out.push(JSON.stringify(j.delta));
|
|
115
123
|
if (j.usage) out.push(usageText(j.usage));
|
|
124
|
+
if (j.usageMetadata) out.push(usageText(j.usageMetadata));
|
|
125
|
+
for (const candidate of j.candidates ?? []) {
|
|
126
|
+
if (candidate.finishReason) out.push(`finish=${candidate.finishReason}`);
|
|
127
|
+
for (const part of candidate.content?.parts ?? []) {
|
|
128
|
+
if (part.text) out.push(`${part.thought === true ? 'thought: ' : ''}${oneLine(part.text, 80)}`);
|
|
129
|
+
if (part.functionCall) out.push(`functionCall ${part.functionCall.name ?? ''}`);
|
|
130
|
+
if (part.thoughtSignature) out.push(`thoughtSignature ${fmtInt(part.thoughtSignature.length)} 字符`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
116
133
|
if (Array.isArray(j.choices)) {
|
|
117
134
|
for (const c of j.choices) {
|
|
118
135
|
if (c.finish_reason) out.push(`finish=${c.finish_reason}`);
|
|
@@ -130,11 +147,13 @@ export function usageText(u) {
|
|
|
130
147
|
const pick = (...ks) => { for (const k of ks) { const v = k.split('.').reduce((o, p) => o?.[p], u); if (typeof v === 'number') return v; } return null; };
|
|
131
148
|
const parts = [];
|
|
132
149
|
const add = (label, v) => { if (v != null) parts.push(`${label} ${fmtInt(v)}`); };
|
|
133
|
-
|
|
134
|
-
add('
|
|
135
|
-
|
|
150
|
+
const prompt = pick('promptTokenCount'), toolInput = pick('toolUsePromptTokenCount');
|
|
151
|
+
add('in', pick('input_tokens', 'prompt_tokens') ?? (prompt !== null ? prompt + (toolInput ?? 0) : null));
|
|
152
|
+
const candidates = pick('candidatesTokenCount'), thoughts = pick('thoughtsTokenCount');
|
|
153
|
+
add('out', pick('output_tokens', 'completion_tokens') ?? (candidates !== null || thoughts !== null ? (candidates ?? 0) + (thoughts ?? 0) : null));
|
|
154
|
+
add('cached', pick('input_tokens_details.cached_tokens', 'cache_read_input_tokens', 'prompt_cache_hit_tokens', 'prompt_tokens_details.cached_tokens', 'cachedContentTokenCount'));
|
|
136
155
|
add('cache_write', pick('cache_creation_input_tokens'));
|
|
137
|
-
add('reasoning', pick('output_tokens_details.reasoning_tokens', 'completion_tokens_details.reasoning_tokens'));
|
|
156
|
+
add('reasoning', pick('output_tokens_details.reasoning_tokens', 'completion_tokens_details.reasoning_tokens', 'thoughtsTokenCount'));
|
|
138
157
|
return parts.join(' / ');
|
|
139
158
|
}
|
|
140
159
|
|
|
@@ -290,6 +309,7 @@ export function finalObject(resp) {
|
|
|
290
309
|
if (data.some((e) => typeof e.json.type === 'string' && e.json.type.startsWith('response.'))) return fromResponses(data);
|
|
291
310
|
if (data.some((e) => e.json.type === 'message_start')) return fromMessages(data);
|
|
292
311
|
if (data.some((e) => Array.isArray(e.json.choices))) return fromChat(data);
|
|
312
|
+
if (data.some((e) => Array.isArray(e.json.candidates) || e.json.usageMetadata)) return fromGemini(data);
|
|
293
313
|
return { value: data.map((e) => e.json), note: '无法识别的事件格式:显示全部事件的 data' };
|
|
294
314
|
}
|
|
295
315
|
|
|
@@ -374,3 +394,36 @@ function fromChat(data) {
|
|
|
374
394
|
out.choices = choices;
|
|
375
395
|
return { value: out, note: '由 Chat SSE chunk 合成(delta 按 choice/tool_call 合并)' };
|
|
376
396
|
}
|
|
397
|
+
|
|
398
|
+
function plainGeminiText(part) {
|
|
399
|
+
return part && typeof part.text === 'string' && Object.keys(part).every(key => key === 'text' || key === 'thought');
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
function fromGemini(data) {
|
|
403
|
+
const out = {};
|
|
404
|
+
const candidates = new Map();
|
|
405
|
+
for (const { json: j } of data) {
|
|
406
|
+
// Usage reports are cumulative; retain the latest report without summing it.
|
|
407
|
+
const { candidates: incoming, ...metadata } = j;
|
|
408
|
+
Object.assign(out, structuredClone(metadata));
|
|
409
|
+
for (const candidate of incoming ?? []) {
|
|
410
|
+
const index = candidate.index ?? 0;
|
|
411
|
+
let value = candidates.get(index);
|
|
412
|
+
if (!value) candidates.set(index, value = { index });
|
|
413
|
+
const { content, ...fields } = candidate;
|
|
414
|
+
Object.assign(value, structuredClone(fields));
|
|
415
|
+
if (!content) continue;
|
|
416
|
+
const { parts = [], ...contentFields } = content;
|
|
417
|
+
value.content ??= { parts: [] };
|
|
418
|
+
Object.assign(value.content, structuredClone(contentFields));
|
|
419
|
+
for (const part of parts) {
|
|
420
|
+
const previous = value.content.parts.at(-1);
|
|
421
|
+
// Never join signed parts or move a signature onto another part.
|
|
422
|
+
if (plainGeminiText(previous) && plainGeminiText(part) && previous.thought === part.thought) previous.text += part.text;
|
|
423
|
+
else value.content.parts.push(structuredClone(part));
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
out.candidates = [...candidates.values()];
|
|
428
|
+
return { value: out, note: '由 Gemini SSE chunk 合成;仅合并相邻的无签名文字,保留签名所在 part;未补造终止状态。' };
|
|
429
|
+
}
|
package/ui/latency.js
CHANGED
|
@@ -58,6 +58,12 @@ function eventKinds(data, visibleOnly) {
|
|
|
58
58
|
default: return [];
|
|
59
59
|
}
|
|
60
60
|
default:
|
|
61
|
+
if (Array.isArray(data?.candidates)) {
|
|
62
|
+
return data.candidates.flatMap(candidate => array(candidate.content?.parts).flatMap(part => [
|
|
63
|
+
...(present(part.text) ? [part.thought === true ? 'reasoning' : 'text'] : []),
|
|
64
|
+
...(present(part.functionCall?.name) ? ['tool'] : []),
|
|
65
|
+
]));
|
|
66
|
+
}
|
|
61
67
|
return array(data?.choices).flatMap(choice => {
|
|
62
68
|
const delta = choice?.delta ?? choice?.message;
|
|
63
69
|
if (!delta) return [];
|