| 40 | } |
| 41 | |
| 42 | export class SDKRpcClient extends SDKRpcClientBase { |
| 43 | readonly homeDir: string; |
| 44 | readonly configPath: string; |
| 45 | readonly identity: KimiHostIdentity | undefined; |
| 46 | readonly telemetry: TelemetryClient; |
| 47 | readonly auth: KimiAuthFacade; |
| 48 | readonly core: KimiCore; |
| 49 | |
| 50 | private readonly ready: Promise<RPCMethods<CoreAPI>>; |
| 51 | |
| 52 | constructor(options: SDKRpcClientOptions = {}) { |
| 53 | super(); |
| 54 | this.identity = |
| 55 | options.identity === undefined ? undefined : assertKimiHostIdentity(options.identity); |
| 56 | this.homeDir = resolveKimiHome(options.homeDir); |
| 57 | this.configPath = resolveConfigPath({ |
| 58 | homeDir: this.homeDir, |
| 59 | configPath: options.configPath, |
| 60 | }); |
| 61 | this.telemetry = options.telemetry ?? noopTelemetryClient; |
| 62 | this.auth = new KimiAuthFacade({ |
| 63 | homeDir: this.homeDir, |
| 64 | configPath: this.configPath, |
| 65 | identity: this.identity, |
| 66 | onRefresh: options.onOAuthRefresh, |
| 67 | }); |
| 68 | |
| 69 | void getRootLogger().configure(resolveLoggingConfig({ homeDir: this.homeDir })); |
| 70 | |
| 71 | const [coreRpc, sdkRpc] = createRPC<CoreAPI, SDKAPI>(); |
| 72 | this.core = new KimiCore(coreRpc, { |
| 73 | homeDir: options.homeDir, |
| 74 | configPath: this.configPath, |
| 75 | kimiRequestHeaders: this.createKimiRequestHeaders(), |
| 76 | resolveOAuthTokenProvider: |
| 77 | options.resolveOAuthTokenProvider ?? this.auth.resolveOAuthTokenProvider, |
| 78 | skillDirs: options.skillDirs, |
| 79 | telemetry: this.telemetry, |
| 80 | appVersion: this.identity?.version, |
| 81 | }); |
| 82 | this.ready = sdkRpc(new ClientAPI(this)); |
| 83 | } |
| 84 | |
| 85 | async ensureConfigFile(): Promise<void> { |
| 86 | await ensureConfigFile(this.configPath); |
| 87 | } |
| 88 | |
| 89 | async close(): Promise<void> { |
| 90 | try { |
| 91 | await getRootLogger().flush(); |
| 92 | } catch { |
| 93 | // never let logger flush block process exit |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | protected async getRpc(): Promise<RPCMethods<CoreAPI>> { |
| 98 | return this.ready; |
| 99 | } |
nothing calls this directly
no outgoing calls
no test coverage detected