mirror of
https://github.com/MoonshotAI/kimi-code.git
synced 2026-08-11 09:47:40 +00:00
feat(cli): wire the CLI host identity into the kimi web server
kimi web now passes createKimiCodeHostIdentity(version) as the server's hostIdentity, so web-UI OAuth flows and the engine's outbound requests carry the explicit CLI identity (productName + version + platform). The explicit hostRequestHeadersSeed is dropped — kap-server derives the same headers from hostIdentity — and buildKimiDefaultHeaders goes away with its only consumer.
This commit is contained in:
parent
1bb734bcf6
commit
023fec54f4
3 changed files with 6 additions and 29 deletions
|
|
@ -11,7 +11,6 @@
|
|||
import { existsSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
|
||||
import { hostRequestHeadersSeed } from '@moonshot-ai/agent-core-v2';
|
||||
import { createServerLogger, startServer, type ServerLogger } from '@moonshot-ai/kap-server';
|
||||
import { shutdownTelemetry, track } from '@moonshot-ai/kimi-telemetry';
|
||||
import chalk from 'chalk';
|
||||
|
|
@ -25,7 +24,7 @@ import { getDataDir } from '#/utils/paths';
|
|||
|
||||
import { initializeServerTelemetry } from '../../telemetry';
|
||||
import {
|
||||
buildKimiDefaultHeaders,
|
||||
createKimiCodeHostIdentity,
|
||||
getHostPackageRoot,
|
||||
getVersion,
|
||||
} from '../../version';
|
||||
|
|
@ -279,13 +278,10 @@ async function runServerInProcess(
|
|||
// Report the CLI's product version as `server_version` (/meta, web UI)
|
||||
// rather than kap-server's private package version.
|
||||
serverVersion: version,
|
||||
// Temporary CLI identity wiring: the full host-identity hookup lands in
|
||||
// step 5 of the host-identity unification.
|
||||
hostIdentity: {
|
||||
productName: 'kimi-code-cli',
|
||||
version,
|
||||
platform: 'kimi_code_cli',
|
||||
},
|
||||
// The CLI's host identity: feeds the engine's bootstrap client identity
|
||||
// and the derived outbound headers (User-Agent + X-Msh-*), so web-UI
|
||||
// OAuth flows and model / WebSearch requests carry the CLI identity.
|
||||
hostIdentity: createKimiCodeHostIdentity(version),
|
||||
logLevel: options.logLevel,
|
||||
logger,
|
||||
debugEndpoints: options.debugEndpoints,
|
||||
|
|
@ -298,10 +294,6 @@ async function runServerInProcess(
|
|||
// `telemetry` toggle). Complements the v1 client registered above, which
|
||||
// only covers host-level events.
|
||||
telemetry: true,
|
||||
// Seed the CLI's Kimi identity headers so the engine's outbound
|
||||
// requests (model, WebSearch, FetchURL) carry the same User-Agent +
|
||||
// X-Msh-* identity as direct CLI runs.
|
||||
seeds: hostRequestHeadersSeed(buildKimiDefaultHeaders(version)),
|
||||
webAssetsDir,
|
||||
});
|
||||
logger.info('serving the REST/WS API and the bundled web UI');
|
||||
|
|
|
|||
|
|
@ -7,11 +7,10 @@
|
|||
import { existsSync, readFileSync } from 'node:fs';
|
||||
import { dirname, resolve } from 'node:path';
|
||||
|
||||
import { createKimiDefaultHeaders, createKimiUserAgent, KIMI_CODE_PLATFORM, type KimiHostIdentity } from '@moonshot-ai/kimi-code-oauth';
|
||||
import { createKimiUserAgent, KIMI_CODE_PLATFORM, type KimiHostIdentity } from '@moonshot-ai/kimi-code-oauth';
|
||||
|
||||
import { CLI_USER_AGENT_PRODUCT } from '#/constant/app';
|
||||
|
||||
import { getDataDir } from '../utils/paths';
|
||||
import { KIMI_BUILD_INFO } from './build-info';
|
||||
|
||||
const MODULE_DIR = import.meta.dirname;
|
||||
|
|
@ -63,10 +62,3 @@ export function createKimiCodeHostIdentity(version = getVersion()): KimiHostIden
|
|||
export function createKimiCodeUserAgent(version = getVersion()): string {
|
||||
return createKimiUserAgent(createKimiCodeHostIdentity(version));
|
||||
}
|
||||
|
||||
export function buildKimiDefaultHeaders(version: string): Record<string, string> {
|
||||
return createKimiDefaultHeaders({
|
||||
homeDir: getDataDir(),
|
||||
...createKimiCodeHostIdentity(version),
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import { dirname, join } from 'node:path';
|
|||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import {
|
||||
buildKimiDefaultHeaders,
|
||||
createKimiCodeUserAgent,
|
||||
getHostPackageJsonPath,
|
||||
getHostPackageRoot,
|
||||
|
|
@ -21,12 +20,6 @@ describe('cli version helpers', () => {
|
|||
expect(getVersion()).toBe(pkg.version);
|
||||
});
|
||||
|
||||
it('builds default headers with the kimi-code-cli user-agent', () => {
|
||||
const headers = buildKimiDefaultHeaders('1.2.3');
|
||||
|
||||
expect(headers['User-Agent']).toBe('kimi-code-cli/1.2.3');
|
||||
});
|
||||
|
||||
it('builds the product user-agent for ad-hoc fetches', () => {
|
||||
expect(createKimiCodeUserAgent('1.2.3')).toBe('kimi-code-cli/1.2.3');
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue