Download packages/agent-core-v2/src/app/authLegacy/authLegacyService.ts from SaylorTwift/kimi-code: direct link, hf CLI and curl.
- Browser
- Download file 2.42 kB
-
https://huggingface.co/SaylorTwift/kimi-code/resolve/main/packages/agent-core-v2/src/app/authLegacy/authLegacyService.ts
- Command line
-
hf download hf://SaylorTwift/kimi-code/packages/agent-core-v2/src/app/authLegacy/authLegacyService.ts
-
curl -L -o authLegacyService.ts https://huggingface.co/SaylorTwift/kimi-code/resolve/main/packages/agent-core-v2/src/app/authLegacy/authLegacyService.ts
2.42 kB
| import { KIMI_CODE_PROVIDER_NAME } from '@moonshot-ai/kimi-code-oauth'; | |
| import type { AuthSummary } from './authLegacy'; | |
| import { LifecycleScope } from '#/app/scopes'; | |
| import { ScopeActivation, registerScopedService } from '#/_base/di/scope'; | |
| import { IOAuthService } from '#/app/auth/auth'; | |
| import { IConfigService } from '#/app/config/config'; | |
| import { | |
| DEFAULT_MODEL_SECTION, | |
| DEFAULT_PROVIDER_SECTION, | |
| MODELS_SECTION, | |
| PROVIDERS_SECTION, | |
| } from '#/app/kosongConfig/configSection'; | |
| import { resolveModelForReady } from '#/llm-adapter/model/model-auth'; | |
| import type { ModelRecord } from '#/llm-adapter/model/model'; | |
| import type { ProviderConfig } from '#/llm-adapter/provider/provider'; | |
| import { IAuthLegacyService } from './authLegacy'; | |
| const MANAGED_PROVIDER_NAME = KIMI_CODE_PROVIDER_NAME; | |
| export class AuthLegacyService implements IAuthLegacyService { | |
| declare readonly _serviceBrand: undefined; | |
| constructor( | |
| private readonly config: IConfigService, | |
| private readonly oauth: IOAuthService, | |
| ) {} | |
| async get(): Promise<AuthSummary> { | |
| await this.config.ready; | |
| const snapshot = this.config.getAll(); | |
| const providers = (snapshot[PROVIDERS_SECTION] ?? {}) as Readonly< | |
| Record<string, ProviderConfig> | |
| >; | |
| const models = (snapshot[MODELS_SECTION] ?? {}) as Readonly<Record<string, ModelRecord>>; | |
| const defaultModel = snapshot[DEFAULT_MODEL_SECTION] as string | undefined; | |
| const defaultProvider = snapshot[DEFAULT_PROVIDER_SECTION] as string | undefined; | |
| const providers_count = Object.keys(providers).length; | |
| const models_ready = resolveModelForReady(defaultModel, models, providers, defaultProvider).resolved; | |
| let managed_provider: AuthSummary['managed_provider'] = null; | |
| if (providers[MANAGED_PROVIDER_NAME] !== undefined) { | |
| const loggedIn = await this.managedLoggedIn(); | |
| managed_provider = { | |
| name: MANAGED_PROVIDER_NAME, | |
| status: loggedIn ? 'authenticated' : 'unauthenticated', | |
| }; | |
| } | |
| return { models_ready, providers_count, managed_provider }; | |
| } | |
| private async managedLoggedIn(): Promise<boolean> { | |
| try { | |
| return (await this.oauth.status(MANAGED_PROVIDER_NAME)).loggedIn; | |
| } catch { | |
| return false; | |
| } | |
| } | |
| } | |
| registerScopedService( | |
| LifecycleScope.App, | |
| IAuthLegacyService, | |
| AuthLegacyService, | |
| ScopeActivation.OnScopeCreated, | |
| 'authLegacy', | |
| ); | |