@jeffreycao/copilot-api 2.7.18 → 2.7.19

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
@@ -55,8 +55,8 @@ bunx --bun @jeffreycao/copilot-api start
55
55
  Use `--bun` to select the Bun runtime and omit `@latest` for routine starts to reuse the cache. See [Bun setup](docs/guides/en/getting-started.md#using-with-bun) for global installation and upgrades.
56
56
 
57
57
  > [!NOTE]
58
- > To trust system-installed CA certificates (for example, behind a corporate HTTPS proxy), set `NODE_USE_SYSTEM_CA=1` before running `npx` or `bunx`: `export NODE_USE_SYSTEM_CA=1` in bash/zsh, or `$env:NODE_USE_SYSTEM_CA="1"` in PowerShell.
59
- > Supported by Bun >= 1.4.0 and [Node.js >= 22.19.0 (22.x) or >= 24.6.0](https://nodejs.org/api/cli.html#node_use_system_ca1). Desktop enables this for server subprocesses by default, preserving explicit environment settings.
58
+ > To trust system-installed CA certificates (for example, behind a corporate HTTPS proxy), `npx` needs no extra configuration: Node.js >= 22.19.0 merges the system CA store at startup through [`tls.setDefaultCACertificates()`](https://nodejs.org/api/tls.html#tlssetdefaultcacertificatescerts). Only Bun requires `NODE_USE_SYSTEM_CA=1` before `bunx --bun`: `export NODE_USE_SYSTEM_CA=1` in bash/zsh, or `$env:NODE_USE_SYSTEM_CA="1"` in PowerShell (Bun >= 1.4.0).
59
+ > Desktop enables the variable for server subprocesses by default, preserving explicit environment settings.
60
60
 
61
61
  Verify the gateway is up:
62
62
 
package/README.zh-CN.md CHANGED
@@ -59,8 +59,8 @@ bunx --bun @jeffreycao/copilot-api start
59
59
  `--bun` 用于选择 Bun 运行时,日常启动省略 `@latest` 以复用缓存。全局安装与升级方式见 [Bun 使用说明](docs/guides/zh-CN/getting-started.md#using-with-bun)。
60
60
 
61
61
  > [!NOTE]
62
- > 如需信任系统安装的 CA 证书(例如使用企业 HTTPS 代理时),请在运行 `npx` 或 `bunx` 前设置 `NODE_USE_SYSTEM_CA=1`:bash/zsh 使用 `export NODE_USE_SYSTEM_CA=1`,PowerShell 使用 `$env:NODE_USE_SYSTEM_CA="1"`。
63
- > 支持 Bun >= 1.4.0,以及 [Node.js >= 22.19.0(22.x)或 >= 24.6.0](https://nodejs.org/api/cli.html#node_use_system_ca1)。Desktop 默认对子进程启用此设置,并保留显式配置的环境变量。
62
+ > 如需信任系统安装的 CA 证书(例如使用企业 HTTPS 代理时),`npx` 无需额外设置:Node.js >= 22.19.0 启动时会通过 [`tls.setDefaultCACertificates()`](https://nodejs.org/api/tls.html#tlssetdefaultcacertificatescerts) 自动合并系统 CA 证书。只有 Bun 需要在运行 `bunx --bun` 前设置 `NODE_USE_SYSTEM_CA=1`:bash/zsh 使用 `export NODE_USE_SYSTEM_CA=1`,PowerShell 使用 `$env:NODE_USE_SYSTEM_CA="1"`(Bun >= 1.4.0)。
63
+ > Desktop 默认对子进程启用此设置,并保留显式配置的环境变量。
64
64
 
65
65
  验证网关已启动:
66
66
 
package/dist/main.js CHANGED
@@ -30,7 +30,7 @@ if (isMcpFastPath(process.argv)) {
30
30
  const { auth } = await import("./auth-Dv6K056n.js");
31
31
  const { debug } = await import("./debug-C26JAmhE.js");
32
32
  const { mcp } = await import("./mcp-Dd_hxxuG.js");
33
- const { start } = await import("./start-Xf1MJrNI.js");
33
+ const { start } = await import("./start-BiKN2HN7.js");
34
34
  const { provider } = await import("./provider-BkN9E04x.js");
35
35
  await runMain(defineCommand({
36
36
  meta: {
@@ -7072,16 +7072,16 @@ const MESSAGES_COMPACTION_PROMPT = [
7072
7072
  ].join("\n");
7073
7073
  const MESSAGES_TOOL_CALL_TIPS = [
7074
7074
  "# Tool Call Tips",
7075
- "- Do NOT call `exec_command` directly; that tool does not exist. Use `functions__exec` to run commands instead.",
7076
- "- The functions__exec tool accepts parameters only as {\"input\":\"...\"}; put the complete executable code inside input, including properly constructed tools.exec_command(...) calls and text(...) output handling.",
7075
+ "- Do NOT call `exec_command` directly; that tool does not exist. Use `functions.exec` (tool name: `exec`) to run commands instead.",
7076
+ "- The functions.exec tool accepts parameters only as {\"input\":\"...\"}; put the complete executable code inside input, including properly constructed tools.exec_command(...) calls and text(...) output handling.",
7077
7077
  "- Construct all tools.exec_command(...) arguments strictly according to its tool definition, and use OS/shell-compatible commands for Windows, Linux, and macOS.",
7078
7078
  "- Always assign the awaited tools.exec_command(...) call to a variable and forward the full result with text(JSON.stringify(r)); unforwarded output is silently dropped and makes results look empty.",
7079
- "- Yielded execution is not truncated output. Resume a running `cell_id` with `functions.wait`, and a live `session_id` with `tools.write_stdin`, until the command reaches a terminal result.",
7079
+ "- Yielded execution is not truncated output. Resume a running `cell_id` with `functions.wait` (tool name: `wait`), and a live `session_id` with `tools.write_stdin`, until the command reaches a terminal result.",
7080
7080
  "- Read files with the OS-native command (Get-Content/Test-Path on Windows PowerShell, cat/ls on POSIX), quote paths containing spaces, and verify the forwarded output is non-empty before concluding a file was read.",
7081
7081
  "- For long-running commands, keep the returned `session_id` and poll it with `tools.write_stdin` until the command finishes; do not redirect output to a temp file and read it back in a second call.",
7082
- "- If `functions__exec` returns `aborted`, retry at most 3 times. After 3 failures, terminate immediately and inform the user that `functions__exec` is unavailable."
7082
+ "- If `functions.exec` returns `aborted`, retry at most 3 times. After 3 failures, terminate immediately and inform the user that `functions.exec` is unavailable."
7083
7083
  ].join("\n");
7084
- const MESSAGES_BATCH_TOOL_CALL_TIPS = ["- Parallel tool calls are disabled for this request. Batch independent commands in one functions__exec call; keep dependent operations sequential.", "const results = await Promise.allSettled([tools.exec_command({cmd: \"git status --short\"})]); for (const result of results) text(JSON.stringify(result.status === \"fulfilled\" ? result.value : {error: String(result.reason)}))"].join("\n");
7084
+ const MESSAGES_BATCH_TOOL_CALL_TIPS = ["- Parallel tool calls are disabled for this request. Batch independent commands in one functions.exec call; keep dependent operations sequential.", "const results = await Promise.allSettled([tools.exec_command({cmd: \"git status --short\"})]); for (const result of results) text(JSON.stringify(result.status === \"fulfilled\" ? result.value : {error: String(result.reason)}))"].join("\n");
7085
7085
  const JSON_OUTPUT_CONSTRAINT = "Do not wrap the JSON in markdown code fences and do not add any text outside the JSON object.";
7086
7086
  const buildOutputFormatInstruction = (format) => {
7087
7087
  if (!format) return null;
@@ -7117,8 +7117,9 @@ function translateResponsesToMessages(payload, options) {
7117
7117
  const registry = createToolRegistry(payload, options.model);
7118
7118
  const normalized = normalizeResponsesInput(payload.input);
7119
7119
  const outputFormatInstruction = buildOutputFormatInstruction(payload.text?.format);
7120
- const { messages, system } = translateInputToAnthropic(normalized.input, registry, payload.instructions, payload.input, options.toolCallTips ?? false);
7121
- if (options.toolCallTips && payload.parallel_tool_calls === false) appendToolCallTips(system, MESSAGES_BATCH_TOOL_CALL_TIPS);
7120
+ const toolCallTips = (options.toolCallTips ?? false) && !hasExecCommandTool(payload);
7121
+ const { messages, system } = translateInputToAnthropic(normalized.input, registry, payload.instructions, payload.input, toolCallTips);
7122
+ if (toolCallTips && payload.parallel_tool_calls === false) appendToolCallTips(system, MESSAGES_BATCH_TOOL_CALL_TIPS);
7122
7123
  if (normalized.compaction) messages.push({
7123
7124
  role: "user",
7124
7125
  content: MESSAGES_COMPACTION_PROMPT
@@ -7303,9 +7304,34 @@ function createToolRegistry(payload, model) {
7303
7304
  if (Array.isArray(payload.input)) for (const item of payload.input) {
7304
7305
  if (getItemType(item) !== "additional_tools") continue;
7305
7306
  for (const tool of getArrayField(item, "tools")) registerTool(tool, registry, strictCustomTools);
7307
+ break;
7306
7308
  }
7307
7309
  return registry;
7308
7310
  }
7311
+ const EXEC_COMMAND_TOOL_NAME = "exec_command";
7312
+ /**
7313
+ * Reports whether the request exposes a direct `exec_command` tool, at the top
7314
+ * level, inside a namespace, or through `input.additional_tools`. The
7315
+ * additional_tools items are scanned in place, so no tool list is copied.
7316
+ */
7317
+ function hasExecCommandTool(payload) {
7318
+ if ((payload.tools ?? []).some(isExecCommandTool)) return true;
7319
+ if (!Array.isArray(payload.input)) return false;
7320
+ for (const item of payload.input) {
7321
+ if (getItemType(item) !== "additional_tools") continue;
7322
+ if (getArrayField(item, "tools").some(isExecCommandTool)) return true;
7323
+ break;
7324
+ }
7325
+ return false;
7326
+ }
7327
+ function isExecCommandTool(tool) {
7328
+ if (getStringField$1(tool, "name") === EXEC_COMMAND_TOOL_NAME) return true;
7329
+ if (!isNamespaceTool(tool)) return false;
7330
+ return tool.tools.some(isExecCommandTool);
7331
+ }
7332
+ function isNamespaceTool(tool) {
7333
+ return getStringField$1(tool, "type") === "namespace";
7334
+ }
7309
7335
  function registerTool(tool, registry, strictCustomTools, namespaces = []) {
7310
7336
  if (!isRecord$1(tool)) throw new ResponsesMessagesTranslationError("Invalid Responses tool definition");
7311
7337
  const type = getStringField$1(tool, "type");
@@ -7348,7 +7374,7 @@ function registerMessagesTool(registration, registry, strictCustomTools) {
7348
7374
  function createMessagesToolDescriptor(registration, registry) {
7349
7375
  const originalKey = createOriginalToolKey(registration);
7350
7376
  return {
7351
- alias: createToolAlias(registration.namespace ? `${registration.namespace.replaceAll(".", "_")}__${registration.name}` : registration.name, originalKey, registry),
7377
+ alias: createToolAlias(registration.namespace && registration.namespace !== "functions" ? `${registration.namespace.replaceAll(".", "_")}__${registration.name}` : registration.name, originalKey, registry),
7352
7378
  kind: registration.kind,
7353
7379
  name: registration.name,
7354
7380
  ...registration.namespace ? { namespace: registration.namespace } : {}
@@ -7484,12 +7510,14 @@ function translateInputReasoning(item, messages) {
7484
7510
  }
7485
7511
  function translateInputToolCall(item, kind, messages, registry) {
7486
7512
  if (!isRecord$1(item)) throw new ResponsesMessagesTranslationError("Invalid Responses tool call item");
7513
+ const name = requireStringField(item, "name", `${kind}_tool_call`);
7514
+ const namespace = getOptionalStringField(item, "namespace") ?? void 0;
7487
7515
  const toolIdentity = {
7488
7516
  kind,
7489
- name: requireStringField(item, "name", `${kind}_tool_call`),
7490
- namespace: getOptionalStringField(item, "namespace") ?? void 0
7517
+ name,
7518
+ namespace
7491
7519
  };
7492
- const descriptor = registry.byOriginal.get(createOriginalToolKey(toolIdentity)) ?? createMessagesToolDescriptor(toolIdentity, registry);
7520
+ const descriptor = findOriginalDescriptor(registry, kind, name, namespace) ?? createMessagesToolDescriptor(toolIdentity, registry);
7493
7521
  const input = kind === "custom" ? { input: getStringField$1(item, "input") ?? "" } : parseFunctionArguments(getStringField$1(item, "arguments") ?? "{}", `${kind}_tool_call.arguments`);
7494
7522
  appendAssistantBlock(messages, {
7495
7523
  type: "tool_use",
@@ -7755,16 +7783,15 @@ function parseDataUrl(value) {
7755
7783
  };
7756
7784
  }
7757
7785
  function findOriginalDescriptor(registry, kind, name, namespace) {
7758
- const matches = [];
7759
- for (const descriptor of registry.byOriginal.values()) {
7760
- if (descriptor.kind !== kind || descriptor.name !== name) continue;
7761
- if (namespace !== void 0) {
7762
- if (descriptor.namespace === namespace) return descriptor;
7763
- continue;
7764
- }
7765
- matches.push(descriptor);
7766
- }
7767
- return matches.find((descriptor) => descriptor.namespace === void 0) ?? (matches.length === 1 ? matches[0] : void 0);
7786
+ return registry.byOriginal.get(createOriginalToolKey({
7787
+ kind,
7788
+ name,
7789
+ namespace
7790
+ })) ?? (!namespace ? registry.byOriginal.get(createOriginalToolKey({
7791
+ kind,
7792
+ name,
7793
+ namespace: "functions"
7794
+ })) : void 0);
7768
7795
  }
7769
7796
  function createOriginalToolKey(tool) {
7770
7797
  return [
@@ -12196,12 +12223,6 @@ const FALLBACK_BASE_INSTRUCTIONS = FALLBACK_CODEX_MODELS.find((model) => model.b
12196
12223
  function isCodexUserAgent(userAgent) {
12197
12224
  return CODEX_USER_AGENT_PATTERN.test(userAgent?.trim() ?? "");
12198
12225
  }
12199
- function isDeepSeekModelId(modelId) {
12200
- return modelId.toLowerCase().includes("deepseek");
12201
- }
12202
- function shouldInjectMessagesToolCallTips(userAgent, targetModel) {
12203
- return isCodexUserAgent(userAgent) && !isDeepSeekModelId(targetModel);
12204
- }
12205
12226
  /**
12206
12227
  * Proxies a models request to the fixed Codex upstream models endpoint.
12207
12228
  * Returns a 404 JSON response when the codex provider is unavailable.
@@ -12323,7 +12344,6 @@ function createSyntheticCodexModel(candidate, template, priority) {
12323
12344
  const defaultReasoningEffort = reasoningEfforts.includes(candidate.defaultReasoningEffort) ? candidate.defaultReasoningEffort : reasoningEfforts[0];
12324
12345
  const supportsReasoning = reasoningEfforts.some((effort) => effort !== "none");
12325
12346
  const inputModalities = [...new Set(candidate.inputModalities)];
12326
- const isDeepSeekModel = isDeepSeekModelId(candidate.slug);
12327
12347
  return {
12328
12348
  ...template,
12329
12349
  slug: candidate.slug,
@@ -12339,11 +12359,11 @@ function createSyntheticCodexModel(candidate, template, priority) {
12339
12359
  apply_patch_tool_type: "freeform",
12340
12360
  web_search_tool_type: "text_and_image",
12341
12361
  supports_search_tool: false,
12342
- use_responses_lite: isDeepSeekModel ? false : true,
12343
- tool_mode: isDeepSeekModel ? null : "code_mode_only",
12362
+ use_responses_lite: true,
12363
+ tool_mode: "code_mode_only",
12344
12364
  multi_agent_version: "v2",
12345
12365
  multi_agent_reasoning_effort: null,
12346
- shell_type: isDeepSeekModel ? "shell_command" : template.shell_type,
12366
+ shell_type: template.shell_type,
12347
12367
  experimental_supported_tools: [],
12348
12368
  input_modalities: inputModalities,
12349
12369
  supports_image_detail_original: false,
@@ -13577,7 +13597,7 @@ async function handleResponsesViaMessages(c, options) {
13577
13597
  }, {
13578
13598
  model: options.targetModel,
13579
13599
  publicModel: options.publicModel,
13580
- toolCallTips: shouldInjectMessagesToolCallTips(c.req.header("user-agent"), options.targetModel)
13600
+ toolCallTips: isCodexUserAgent(c.req.header("user-agent"))
13581
13601
  });
13582
13602
  const context = translation;
13583
13603
  debugJson(logger$3, "Translated Messages request:", {
@@ -14204,4 +14224,4 @@ createServer();
14204
14224
  //#endregion
14205
14225
  export { createServer };
14206
14226
 
14207
- //# sourceMappingURL=server-D8LzQcmu.js.map
14227
+ //# sourceMappingURL=server-DneVQ_F8.js.map