fix(cli): seed host identity headers into the experimental v2 server

The v2 boot path (kimi server run with the experimental flag) now seeds the CLI's Kimi identity headers (User-Agent + X-Msh-* device identity) into the engine through kap-server's seeds option, so outbound model, WebSearch, and FetchURL requests carry the same identity as direct CLI runs. kap-server's own package version is 0.0.0, so the identity has to come from the CLI.
This commit is contained in:
qer 2026-07-11 23:18:18 +08:00
parent 07d8c97ebe
commit dd08a4cfd8
2 changed files with 16 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
"@moonshot-ai/kimi-code": patch
---
Send the CLI identity headers (User-Agent and device identity) with outbound requests from the experimental v2 server, matching direct CLI runs.

View file

@ -26,7 +26,12 @@ import { openUrl as defaultOpenUrl } from '#/utils/open-url';
import { getDataDir } from '#/utils/paths';
import { initializeServerTelemetry } from '../../telemetry';
import { createKimiCodeHostIdentity, getHostPackageRoot, getVersion } from '../../version';
import {
buildKimiDefaultHeaders,
createKimiCodeHostIdentity,
getHostPackageRoot,
getVersion,
} from '../../version';
import {
accessUrlLines,
buildOpenableUrl,
@ -406,6 +411,7 @@ async function runServerInProcess(
// its agent-core-v2 engine are only resolved when the flag is on.
const { createServerLogger: createServerV2Logger, startServer: startServerV2 } =
await import('@moonshot-ai/kap-server');
const { hostRequestHeadersSeed } = await import('@moonshot-ai/agent-core-v2');
const logger = createServerV2Logger({ level: options.logLevel });
const v2 = await startServerV2({
host: options.host,
@ -418,6 +424,10 @@ async function runServerInProcess(
allowRemoteTerminals: options.allowRemoteTerminals,
allowedHosts: options.allowedHosts,
disableAuth: options.dangerousBypassAuth,
// Seed the CLI's Kimi identity headers so the v2 engine's outbound
// requests (model, WebSearch, FetchURL) carry the same User-Agent +
// X-Msh-* identity as direct CLI runs.
seeds: hostRequestHeadersSeed(buildKimiDefaultHeaders(version)),
webAssetsDir: serverWebAssetsDir(),
});
// v2's connection registry exposes no count-change hook, so forward