Files
magpie/internal/gui/assets/headerpresets.js
T
yetone 0d0462d4a2 gui: a Presets menu in a provider's Headers fills in what a common client sends (l3123109756 on X)
The Headers editor gets a small Presets button beside + Add header. It
opens the app menu (openProtoMenu) with Codex CLI, Gemini CLI, OpenCode,
Kilo Code, Cline, Roo Code and Cherry Studio. A pick adds that client's
headers: a header the draft already has with a value keeps the user's own,
one with no value is filled, the rest become rows. The list lives in
headerpresets.js, imported when Presets is pressed, so the core's script
budget is not touched. No Claude Code preset and nothing that imitates it.

Where each value comes from (another app's values come from that app):
- Codex CLI: originator codex_cli_rs and the User-Agent shape from
  codex-rs login/src/auth/default_client.rs (as internal/provider
  codex_request.go sends them), version 0.167.0 = @openai/codex on npm.
- Gemini CLI: GeminiCLI/<ver>/<model> (<platform>; <arch>; terminal) as
  internal/provider/google.go userAgent has it, 0.67.0 = @google/gemini-cli
  on npm.
- OpenCode: opencode/latest/<ver>/cli (packages/core/src/app.ts,
  internal/provider/opencode_client.go), 2.2.7 = @opencode/cli on npm.
- Kilo Code: HTTP-Referer, X-Title, User-Agent, X-KILOCODE-EDITORNAME from
  Kilo-Org/kilocode request.ts and headers.ts (internal/provider/kilo.go),
  7.8.27 = @kilocode/cli on npm.
- Cline: cline/cline sdk/packages/llms/src/providers/cline-client-headers.ts
  (internal/provider/cline.go), desktop client, 3.5.54 as cline.go has it.
- Roo Code: DEFAULT_HEADERS in RooCodeInc/Roo-Code
  src/api/providers/constants.ts, RooCode/3.53.0 = src/package.json on main.
- Cherry Studio: defaultAppHeaders in CherryHQ/cherry-studio
  src/main/utils/http.ts, read from main on 2026-11-11.

Run (mote, at the pushed head, rebased on origin/main):
- new header-presets.test.cjs: 20 of 20 in chromium and webkit, en, zh,
  zh-TW, ja, de, 900px and 420px. With the user-value rule broken by hand
  (a preset overwrote a set value) it was 0 of 20.
- header-session-hint, model-headers, i18n-keys, i18n-en-no-cjk: green.
- TestCoreScriptBudget: ok. app.js is smaller than before.
- editor-hints.test.cjs webkit: 10 red here and on a clean origin/main
  copy alike ("Tab didn't come back to Certificate's box"), filed in
  #5872.
- The whole GUI suite is running on mote after the tag; reds will be
  filed.
Not tried: a real request through a preset's headers against a vendor
that checks them. Codex's and Gemini's User-Agents carry macOS and arm64
as magpie's own Go code does.
2026-11-11 06:38:15 +08:00

39 lines
2.9 KiB
JavaScript

// A provider's Headers can be filled from what a common client sends
// (l3123109756 on X). app.js draws the Presets button and imports this when
// it is pressed, so the list weighs nothing on the core. Each value is that
// client's own, cited above it; none imitates Claude Code. A client's name
// is not translated. Versions are the latest on 2026-11-11.
const HEADER_PRESETS = [
// codex-rs login/src/auth/default_client.rs (originator, User-Agent); @openai/codex 0.167.0 on npm
{ name: "Codex CLI", headers: [["originator", "codex_cli_rs"], ["User-Agent", "codex_cli_rs/0.167.0 (Mac OS 26.6.0; arm64) Apple_Terminal/455"], ["version", "0.167.0"]] },
// google-gemini/gemini-cli's Code Assist User-Agent; @google/gemini-cli 0.67.0 on npm
{ name: "Gemini CLI", headers: [["User-Agent", "GeminiCLI/0.67.0/gemini-2.5-pro (darwin; arm64; terminal)"]] },
// packages/core/src/app.ts: opencode/${channel}/${version}/${name}; @opencode/cli 2.2.7 on npm
{ name: "OpenCode", headers: [["User-Agent", "opencode/latest/2.2.7/cli"]] },
// Kilo-Org/kilocode request.ts and kilo-gateway headers.ts; @kilocode/cli 7.8.27 on npm
{ name: "Kilo Code", headers: [["HTTP-Referer", "https://kilocode.ai"], ["X-Title", "Kilo Code"], ["User-Agent", "Kilo-Code/7.8.27"], ["X-KILOCODE-EDITORNAME", "Kilo CLI 7.8.27"]] },
// cline/cline sdk/packages/llms/src/providers/cline-client-headers.ts, desktop client
{ name: "Cline", headers: [["HTTP-Referer", "https://cline.bot"], ["X-Title", "Cline"], ["X-IS-MULTIROOT", "false"], ["X-CLIENT-TYPE", "cline-desktop"], ["X-CLIENT-VERSION", "3.5.54"], ["User-Agent", "Cline/3.5.54"]] },
// RooCodeInc/Roo-Code src/api/providers/constants.ts DEFAULT_HEADERS; src/package.json 3.53.0
{ name: "Roo Code", headers: [["HTTP-Referer", "https://github.com/RooVetGit/Roo-Cline"], ["X-Title", "Roo Code"], ["User-Agent", "RooCode/3.53.0"]] },
// CherryHQ/cherry-studio src/main/utils/http.ts defaultAppHeaders
{ name: "Cherry Studio", headers: [["HTTP-Referer", "https://cherry-ai.com"], ["X-Title", "Cherry Studio"]] },
];
// applyHeaderPreset adds a preset's headers to the draft: a header the draft
// already has with a value keeps the user's own, one with no value yet is
// filled, the rest become rows.
function applyHeaderPreset(rows, preset) {
for (let i = rows.length - 1; i >= 0; i--) if (!(rows[i][0] || "").trim() && !(rows[i][1] || "").trim()) rows.splice(i, 1);
for (const [k, v] of preset.headers) {
const had = rows.find((r) => (r[0] || "").trim().toLowerCase() === k.toLowerCase());
if (!had) rows.push([k, v, false]);
else if (!(had[1] || "").trim()) had[1] = v;
}
}
window.headerPresetsOpen = function open(b, rows, redraw) {
openProtoMenu(b, HEADER_PRESETS.map((p) => ({ v: p.name, name: p.name, literalName: true, note: "" })), "", (v) => {
applyHeaderPreset(rows, HEADER_PRESETS.find((p) => p.name === v));
redraw();
}, "Presets");
};