MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / handleOpenPlatformLogin

Function handleOpenPlatformLogin

apps/kimi-code/src/tui/commands/auth.ts:102–180  ·  view source on GitHub ↗
(
  host: SlashCommandHost,
  platform: OpenPlatformDefinition,
)

Source from the content-addressed store, hash-verified

100}
101
102async function handleOpenPlatformLogin(
103 host: SlashCommandHost,
104 platform: OpenPlatformDefinition,
105): Promise<void> {
106 const consoleHost = platform.consoleUrl?.replace(/^https?:\/\//, '') ?? '';
107 const platformName = consoleHost.length > 0 ? `Kimi Platform (${consoleHost})` : 'Kimi Platform';
108 const subtitleLines = [
109 `${'base_url'.padEnd(12)}${platform.baseUrl}`,
110 `${'saved to'.padEnd(12)}~/.kimi-code/config.toml`,
111 ];
112 const apiKey = await promptApiKey(host, platformName, subtitleLines);
113 if (apiKey === undefined) return;
114
115 const controller = new AbortController();
116 const cancelLogin = (): void => {
117 controller.abort();
118 };
119 host.cancelInFlight = cancelLogin;
120
121 let models: ManagedKimiCodeModelInfo[];
122 try {
123 models = await fetchOpenPlatformModels(platform, apiKey, fetch, controller.signal);
124 models = filterModelsByPrefix(models, platform);
125 } catch (error) {
126 if (controller.signal.aborted) return;
127 const msg = formatErrorMessage(error);
128 host.showError(`Failed to verify API key: ${msg}`);
129 if (
130 error instanceof OpenPlatformApiError &&
131 error.status === 401
132 ) {
133 host.showStatus(
134 'Hint: If your API key was obtained from Kimi Code, please select "Kimi Code" instead.',
135 );
136 }
137 return;
138 } finally {
139 if (host.cancelInFlight === cancelLogin) {
140 host.cancelInFlight = undefined;
141 }
142 }
143
144 if (models.length === 0) {
145 host.showError('No models available for this platform.');
146 return;
147 }
148
149 const selection = await promptModelSelectionForOpenPlatform(host, models, platform);
150 if (selection === undefined) return;
151
152 const existingConfig = await host.harness.getConfig();
153 if (existingConfig.providers[platform.id] !== undefined) {
154 await host.harness.removeProvider(platform.id);
155 }
156
157 const config = await host.harness.getConfig();
158 applyOpenPlatformConfig(config as ManagedKimiConfigShape, {
159 platform,

Callers 1

handleLoginCommandFunction · 0.85

Calls 13

promptApiKeyFunction · 0.90
formatErrorMessageFunction · 0.90
fetchOpenPlatformModelsFunction · 0.85
filterModelsByPrefixFunction · 0.85
applyOpenPlatformConfigFunction · 0.85
showErrorMethod · 0.65
showStatusMethod · 0.65
getConfigMethod · 0.65
removeProviderMethod · 0.65
setConfigMethod · 0.65

Tested by

no test coverage detected