(
homeDir: string,
options: CreateKimiDeviceIdOptions = {},
)
| 44 | } |
| 45 | |
| 46 | export function createKimiDeviceId( |
| 47 | homeDir: string, |
| 48 | options: CreateKimiDeviceIdOptions = {}, |
| 49 | ): string { |
| 50 | const existing = readKimiDeviceId(homeDir); |
| 51 | if (existing !== null) return existing; |
| 52 | |
| 53 | const id = randomUUID(); |
| 54 | try { |
| 55 | mkdirSync(homeDir, { recursive: true, mode: 0o700 }); |
| 56 | writeFileSync(join(homeDir, 'device_id'), id, { encoding: 'utf-8', mode: 0o600 }); |
| 57 | } catch { |
| 58 | // Best-effort: requests can still use the in-memory id. |
| 59 | } |
| 60 | if (options.onFirstLaunch !== undefined) { |
| 61 | try { |
| 62 | options.onFirstLaunch(id); |
| 63 | } catch { |
| 64 | // Telemetry callback must not affect device id creation. |
| 65 | } |
| 66 | } |
| 67 | return id; |
| 68 | } |
| 69 | |
| 70 | export function createKimiDeviceHeaders(options: { |
| 71 | readonly homeDir: string; |
no test coverage detected