* Generate a per-run connection token for Copilot SDK headless authentication. * Produces 32 random bytes encoded as a 64-character hexadecimal string. * @param {{ randomBytes?: (size: number) => Buffer }} [options] * @returns {string} 64-character hexadecimal token (32 random bytes).
(options)
| 156 | * @returns {string} 64-character hexadecimal token (32 random bytes). |
| 157 | */ |
| 158 | function generateCopilotConnectionToken(options) { |
| 159 | // randomBytes injection exists only for unit tests; production uses crypto.randomBytes. |
| 160 | const randomBytes = options?.randomBytes ?? crypto.randomBytes; |
| 161 | return randomBytes(32).toString("hex"); |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * Determines if the collected output contains a transient CAPIError 400 |
no outgoing calls
no test coverage detected