@jeffreycao/copilot-api 2.2.11 → 2.2.12

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
@@ -264,6 +264,42 @@ enabled = false
264
264
  >
265
265
  > For third-party models that do not support `tool_search`, we recommend disabling features.apps. Otherwise, each prompt may consume an additional 20,000 or more tokens.
266
266
 
267
+ ### If Codex Is Not Signed In to a GPT Account
268
+
269
+ ```toml
270
+ [model_providers.copilot_api]
271
+ name = "OpenAI"
272
+ base_url = "http://localhost:4141"
273
+ requires_openai_auth = false
274
+ supports_websockets = false
275
+ wire_api = "responses"
276
+ request_max_retries = 3
277
+ stream_max_retries = 3
278
+ stream_idle_timeout_ms = 300000
279
+
280
+ [model_providers.copilot_api.auth]
281
+ command = "powershell.exe"
282
+ args = [
283
+ "-NoProfile",
284
+ "-NonInteractive",
285
+ "-Command",
286
+ "[Console]::Out.Write($env:GITHUB_COPILOT_API_KEY)"
287
+ ]
288
+ ```
289
+
290
+ macOS, replace the `auth` block with:
291
+
292
+ ```toml
293
+ [model_providers.copilot_api.auth]
294
+ command = "/bin/zsh"
295
+ args = [
296
+ "-c",
297
+ "printf '%s' \"$GITHUB_COPILOT_API_KEY\""
298
+ ]
299
+ ```
300
+
301
+ Without this configuration, Codex cannot fetch `/v1/models` while not signed in to a GPT account, so custom models are unavailable in the model picker.
302
+
267
303
  When a Codex client (`User-Agent` starts with `codex`) requests the top-level `GET /v1/models`, the gateway merges native Codex models with models available through the Messages adapter. The latter advertise `use_responses_lite: true`: `/v1/responses` uses **Responses → Messages** for Anthropic providers, while OpenAI-compatible providers and Chat-only Copilot models reuse the existing Messages route for **Responses → Messages → Chat Completions**, then translate streaming or JSON results back to Responses.
268
304
 
269
305
  The merged catalog is what Codex shows in its model picker, including the models exposed by your configured providers:
package/README.zh-CN.md CHANGED
@@ -280,6 +280,42 @@ enabled = false
280
280
  >
281
281
  > 对于不支持 `tool_search` 的第三方模型,我们建议禁用 features.apps。否则,每个提示可能会额外消耗 20,000 多个 token。
282
282
 
283
+ ### Codex 未登录 GPT 账号时
284
+
285
+ ```toml
286
+ [model_providers.copilot_api]
287
+ name = "OpenAI"
288
+ base_url = "http://localhost:4141"
289
+ requires_openai_auth = false
290
+ supports_websockets = false
291
+ wire_api = "responses"
292
+ request_max_retries = 3
293
+ stream_max_retries = 3
294
+ stream_idle_timeout_ms = 300000
295
+
296
+ [model_providers.copilot_api.auth]
297
+ command = "powershell.exe"
298
+ args = [
299
+ "-NoProfile",
300
+ "-NonInteractive",
301
+ "-Command",
302
+ "[Console]::Out.Write($env:GITHUB_COPILOT_API_KEY)"
303
+ ]
304
+ ```
305
+
306
+ macOS 将 `auth` 段替换为:
307
+
308
+ ```toml
309
+ [model_providers.copilot_api.auth]
310
+ command = "/bin/zsh"
311
+ args = [
312
+ "-c",
313
+ "printf '%s' \"$GITHUB_COPILOT_API_KEY\""
314
+ ]
315
+ ```
316
+
317
+ 未按上述方式配置时,Codex 未登录 GPT 账号拉不到 `/v1/models`,无法选择自定义模型。
318
+
283
319
  Codex 客户端(`User-Agent` 以 `codex` 开头)请求顶层 `GET /v1/models` 时,网关会把原生 Codex 模型与可通过 Messages 适配的模型合并返回。后者会声明 `use_responses_lite: true`:调用 `/v1/responses` 后,Anthropic provider 走 **Responses → Messages**,OpenAI 兼容 provider 以及只支持 Chat 的 Copilot 模型则复用现有 Messages 路由继续走 **Responses → Messages → Chat Completions**,最终统一翻译回 Responses(包括流式事件)。
284
320
 
285
321
  合并后的模型列表会直接展示在 Codex 的模型选择界面中,包含各 provider 暴露的模型:
package/dist/main.js CHANGED
@@ -30,7 +30,7 @@ if (isMcpFastPath(process.argv)) {
30
30
  const { auth } = await import("./auth-C-RWNXGU.js");
31
31
  const { debug } = await import("./debug-41w6Whae.js");
32
32
  const { mcp } = await import("./mcp-fpSlKZxK.js");
33
- const { start } = await import("./start-DmLlG7PU.js");
33
+ const { start } = await import("./start-CJ6z_8Pn.js");
34
34
  await runMain(defineCommand({
35
35
  meta: {
36
36
  name: "copilot-api",
@@ -8697,17 +8697,11 @@ function registerMessagesTool(registration, registry) {
8697
8697
  const originalKey = createOriginalToolKey(registration);
8698
8698
  const existing = registry.byOriginal.get(originalKey);
8699
8699
  if (existing) return existing;
8700
- const alias = createToolAlias(registration.namespace ? `${registration.namespace.replaceAll(".", "_")}__${registration.name}` : registration.name, originalKey, registry);
8701
- const descriptor = {
8702
- alias,
8703
- kind: registration.kind,
8704
- name: registration.name,
8705
- ...registration.namespace ? { namespace: registration.namespace } : {}
8706
- };
8707
- registry.byAlias.set(alias, descriptor);
8700
+ const descriptor = createMessagesToolDescriptor(registration, registry);
8701
+ registry.byAlias.set(descriptor.alias, descriptor);
8708
8702
  registry.byOriginal.set(originalKey, descriptor);
8709
8703
  registry.tools.push({
8710
- name: alias,
8704
+ name: descriptor.alias,
8711
8705
  ...registration.description ? { description: registration.description } : {},
8712
8706
  input_schema: registration.kind === "custom" ? CUSTOM_TOOL_INPUT_SCHEMA : registration.parameters ?? {
8713
8707
  type: "object",
@@ -8717,6 +8711,15 @@ function registerMessagesTool(registration, registry) {
8717
8711
  });
8718
8712
  return descriptor;
8719
8713
  }
8714
+ function createMessagesToolDescriptor(registration, registry) {
8715
+ const originalKey = createOriginalToolKey(registration);
8716
+ return {
8717
+ alias: createToolAlias(registration.namespace ? `${registration.namespace.replaceAll(".", "_")}__${registration.name}` : registration.name, originalKey, registry),
8718
+ kind: registration.kind,
8719
+ name: registration.name,
8720
+ ...registration.namespace ? { namespace: registration.namespace } : {}
8721
+ };
8722
+ }
8720
8723
  function translateInputToAnthropic(input, registry, instructions, originalInput, toolCallTips) {
8721
8724
  const messages = [];
8722
8725
  const system = [];
@@ -8847,11 +8850,12 @@ function translateInputReasoning(item, messages) {
8847
8850
  }
8848
8851
  function translateInputToolCall(item, kind, messages, registry) {
8849
8852
  if (!isRecord(item)) throw new ResponsesMessagesTranslationError("Invalid Responses tool call item");
8850
- const descriptor = registerMessagesTool({
8853
+ const toolIdentity = {
8851
8854
  kind,
8852
8855
  name: requireStringField(item, "name", `${kind}_tool_call`),
8853
8856
  namespace: getOptionalStringField(item, "namespace") ?? void 0
8854
- }, registry);
8857
+ };
8858
+ const descriptor = registry.byOriginal.get(createOriginalToolKey(toolIdentity)) ?? createMessagesToolDescriptor(toolIdentity, registry);
8855
8859
  const input = kind === "custom" ? { input: getStringField(item, "input") ?? "" } : parseFunctionArguments(getStringField(item, "arguments") ?? "{}", `${kind}_tool_call.arguments`);
8856
8860
  appendAssistantBlock(messages, {
8857
8861
  type: "tool_use",
@@ -10569,4 +10573,4 @@ server.route("/:provider/images", providerImageRoutes);
10569
10573
  //#endregion
10570
10574
  export { server };
10571
10575
 
10572
- //# sourceMappingURL=server-D_qrybxD.js.map
10576
+ //# sourceMappingURL=server-C3DnUZoh.js.map