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

Method constructor

packages/oauth/src/oauth-manager.ts:121–156  ·  view source on GitHub ↗
(options: OAuthManagerOptions)

Source from the content-addressed store, hash-verified

119 private inFlightRefresh: { promise: Promise<string>; force: boolean } | undefined;
120
121 constructor(options: OAuthManagerOptions) {
122 this.config = options.config;
123 this.storage = options.storage;
124 this.refreshThresholdFn = options.refreshThreshold ?? defaultRefreshThreshold;
125 this.deviceCodeTimeoutMs = options.deviceCodeTimeoutMs ?? DEFAULT_DEVICE_CODE_TIMEOUT_MS;
126 this.now = options.now ?? (() => Math.floor(Date.now() / 1000));
127 this.sleep = options.sleep ?? defaultSleep;
128 this.deviceHeaders = options.deviceHeaders;
129 this.onRefresh = options.onRefresh;
130 this.refreshImpl =
131 options.refreshTokenImpl ??
132 ((config, refreshToken, refreshOptions) =>
133 refreshAccessToken(config, refreshToken, {
134 ...refreshOptions,
135 deviceHeaders: this.resolveDeviceHeaders(),
136 }));
137 this.requestImpl =
138 options.requestDeviceImpl ??
139 ((config) =>
140 requestDeviceAuthorization(config, {
141 deviceHeaders: this.resolveDeviceHeaders(),
142 }));
143 this.pollImpl =
144 options.pollDeviceImpl ??
145 ((config, deviceCode) =>
146 pollDeviceToken(config, deviceCode, {
147 deviceHeaders: this.resolveDeviceHeaders(),
148 }));
149 // The `KIMI_CODE_HOME` fallback MUST stay test-only so production
150 // entry points can't silently run without a lock just because the
151 // env happens to be unset. vitest sets `NODE_ENV='test'` by default,
152 // so multi-process test workers still pick up the test home path.
153 const envConfigDir =
154 process.env['NODE_ENV'] === 'test' ? process.env['KIMI_CODE_HOME'] : undefined;
155 this.configDir = options.configDir ?? envConfigDir;
156 }
157
158 private resolveDeviceHeaders(): DeviceHeaders | undefined {
159 return this.deviceHeaders?.();

Callers

nothing calls this directly

Calls 5

resolveDeviceHeadersMethod · 0.95
refreshAccessTokenFunction · 0.90
pollDeviceTokenFunction · 0.90
nowMethod · 0.65

Tested by

no test coverage detected