feat: support custom headers in LLM runner (EVOLVER_LLM_HEADERS)

オープン
#630 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
76/100
issue の種類
機能追加
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
javascript, nodejs
領域
ai, api, backend

調査の方向性

Start by locating llmRunner.js and readLlmRunnerConfig(), then follow how its returned configuration reaches complete(). Support the documented single-header and JSON formats, merge the parsed values with the existing request headers, and verify that requests include custom headers without losing the defaults.

索引モデルが issue の本文から書いたものです。

説明

问题

内置的 llm runner(llmRunner.js)在 complete() 函数中硬编码了 HTTP 请求头:

  • "" + + "" + + "javascript
    headers: { 'content-type': 'application/json', authorization: Bearer \ },
  • "" + + "" + + "" +

某些 OpenAI 兼容的 API 提供商需要额外的请求头来进行路由/认证。例如,OpenCode Go 需要 + "" + x-opencode-session + "" + 头来进行请求路由:

  • "" + + "" + + "json
    {
    "error": {
    "type": "MissingSessionID",
    "message": "Request is missing x-opencode-session and cannot be routed efficiently."
    }
    }
  • "" + + "" + + "" +

没有这个头,API 会返回 400 Bad Request。

建议方案

通过环境变量 + "" + EVOLVER_LLM_HEADERS + "" + 支持自定义请求头:

简单格式(单个头):

  • "" + + "" + + "ash
    export EVOLVER_LLM_HEADERS='x-opencode-session:evolver-autoexec-12345'
  • "" + + "" + + "" +

JSON 格式(多个头):

  • "" + + "" + + "ash
    export EVOLVER_LLM_HEADERS='{"x-opencode-session":"evolver-12345","user-agent":"my-agent/1.0"}'
  • "" + + "" + + "" +

实现建议

在 + "" +
eadLlmRunnerConfig() + "" + 中解析 + "" + EVOLVER_LLM_HEADERS + "" + 并合并到请求头:

  • "" + + "" + + "javascript
    // readLlmRunnerConfig
    const rawHeaders = env['EVOLVER_LLM_HEADERS'] ?? '';
    const extraHeaders = rawHeaders.startsWith('{')
    ? JSON.parse(rawHeaders)
    : Object.fromEntries(rawHeaders.split(',').map(h => h.split(':').map(s => s.trim())));

return { apiKey, baseUrl, model, maxTurns, maxFileBytes, extraHeaders };

// complete()
const response = await fetchFn(\/chat/completions, {
method: 'POST',
headers: {
'content-type': 'application/json',
authorization: \Bearer \,
...config.extraHeaders,
},
body: JSON.stringify({ model: config.model, messages, tools: TOOLS, tool_choice: 'auto' }),
signal,
});

  • "" + + "" + + "" +

临时解决方案

目前使用本地代理来添加所需的请求头,然后转发到上游 API。这虽然可行,但增加了一个额外的进程和网络跳转。

环境信息


Problem

The built-in llm runner (llmRunner.js) hardcodes HTTP headers in the complete() function:

  • "" + + "" + + "javascript
    headers: { 'content-type': 'application/json', authorization: \Bearer \ },
  • "" + + "" + + "" +

Some OpenAI-compatible API providers require additional headers for routing/authentication. For example, OpenCode Go requires + "" + x-opencode-session + "" + for request routing:

  • "" + + "" + + "json
    {
    "error": {
    "type": "MissingSessionID",
    "message": "Request is missing x-opencode-session and cannot be routed efficiently."
    }
    }
  • "" + + "" + + "" +

Without this header, the API returns 400 Bad Request.

Proposed Solution

Add support for custom headers via environment variable + "" + EVOLVER_LLM_HEADERS + "" + :

Simple format (single header):

  • "" + + "" + + "ash
    export EVOLVER_LLM_HEADERS='x-opencode-session:evolver-autoexec-12345'
  • "" + + "" + + "" +

JSON format (multiple headers):

  • "" + + "" + + "ash
    export EVOLVER_LLM_HEADERS='{"x-opencode-session":"evolver-12345","user-agent":"my-agent/1.0"}'
  • "" + + "" + + "" +

Implementation

In + "" +
eadLlmRunnerConfig() + "" + , parse + "" + EVOLVER_LLM_HEADERS + "" + and merge into request headers:

  • "" + + "" + + "javascript
    // readLlmRunnerConfig
    const rawHeaders = env['EVOLVER_LLM_HEADERS'] ?? '';
    const extraHeaders = rawHeaders.startsWith('{')
    ? JSON.parse(rawHeaders)
    : Object.fromEntries(rawHeaders.split(',').map(h => h.split(':').map(s => s.trim())));

return { apiKey, baseUrl, model, maxTurns, maxFileBytes, extraHeaders };

// complete()
const response = await fetchFn(\/chat/completions, {
method: 'POST',
headers: {
'content-type': 'application/json',
authorization: \Bearer \,
...config.extraHeaders,
},
body: JSON.stringify({ model: config.model, messages, tools: TOOLS, tool_choice: 'auto' }),
signal,
});

  • "" + + "" + + "" +

Workaround

Currently using a local proxy that adds the required header before forwarding to the upstream API. This works but adds an extra process and network hop.

Environment

主要言語
JavaScript
スター
9.1k
フォーク
848
平均マージ
14時間 39分
マージ済み PR(30日)
1

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

EvoMap/evolver のほかの issue

EvoMap/evolver の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。