( credentials: ChatGptOAuthCredentials, clientEnv: ClientEnv = env, )
| 128 | } |
| 129 | |
| 130 | export const saveChatGptOAuthCredentials = ( |
| 131 | credentials: ChatGptOAuthCredentials, |
| 132 | clientEnv: ClientEnv = env, |
| 133 | ): void => { |
| 134 | const configDir = getConfigDir(clientEnv) |
| 135 | const credentialsPath = getCredentialsPath(clientEnv) |
| 136 | |
| 137 | ensureDirectoryExistsSync(configDir) |
| 138 | |
| 139 | let existingData: Record<string, unknown> = {} |
| 140 | if (fs.existsSync(credentialsPath)) { |
| 141 | try { |
| 142 | existingData = JSON.parse(fs.readFileSync(credentialsPath, 'utf8')) |
| 143 | } catch { |
| 144 | // Ignore parse errors, start fresh |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | const updatedData = { |
| 149 | ...existingData, |
| 150 | chatgptOAuth: credentials, |
| 151 | } |
| 152 | |
| 153 | fs.writeFileSync(credentialsPath, JSON.stringify(updatedData, null, 2)) |
| 154 | } |
| 155 | |
| 156 | export const clearChatGptOAuthCredentials = ( |
| 157 | clientEnv: ClientEnv = env, |
no test coverage detected