Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/server-ipv6-origin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@moonshot-ai/kimi-code": patch
---

Format IPv6 server host literals with brackets when building server origins.
8 changes: 7 additions & 1 deletion apps/kimi-code/src/cli/sub/server/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { join } from 'node:path';

import type { ServerLogLevel } from '@moonshot-ai/server';

import { formatHostForUrl } from './networks';

export const LOCAL_SERVER_HOST = '127.0.0.1';
export const DEFAULT_LAN_HOST = '0.0.0.0';
export const DEFAULT_SERVER_HOST = LOCAL_SERVER_HOST;
Expand Down Expand Up @@ -158,7 +160,11 @@ export function parseLogLevel(raw: string | undefined): ServerLogLevel {
}

export function serverOrigin(host: string, port: number): string {
return `http://${host}:${port}`;
const formattedHost =
host.startsWith('[') && host.endsWith(']')
? host
: formatHostForUrl(host, host.includes(':') ? 'IPv6' : 'IPv4');
return `http://${formattedHost}:${port}`;
}

/** Strip `/api/v1` and trailing slashes so user-supplied origins are uniform. */
Expand Down
7 changes: 7 additions & 0 deletions apps/kimi-code/test/cli/server/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,13 @@ describe('shared parsers stay strict', () => {
expect(parseLogLevel(undefined)).toBe('info');
expect(parseLogLevel('debug')).toBe('debug');
});

it('wraps IPv6 hosts when formatting server origins', async () => {
const { serverOrigin } = await import('#/cli/sub/server/shared');
expect(serverOrigin('::1', 58627)).toBe('http://[::1]:58627');
expect(serverOrigin('127.0.0.1', 58627)).toBe('http://127.0.0.1:58627');
expect(serverOrigin('[::1]', 58627)).toBe('http://[::1]:58627');
});
});

describe('server web asset directory resolution', () => {
Expand Down