MCPcopy Index your code
hub / github.com/anomalyco/opencode / requestDeviceCode

Function requestDeviceCode

packages/opencode/src/plugin/xai.ts:198–216  ·  view source on GitHub ↗
(options: XaiAuthPluginOptions = {})

Source from the content-addressed store, hash-verified

196}
197
198export async function requestDeviceCode(options: XaiAuthPluginOptions = {}): Promise<DeviceCodeResponse> {
199 const response = await fetch(options.deviceAuthorizationUrl ?? DEVICE_AUTHORIZATION_URL, {
200 method: "POST",
201 headers: authHeaders(),
202 body: new URLSearchParams({
203 client_id: CLIENT_ID,
204 scope: SCOPE,
205 }).toString(),
206 })
207 if (!response.ok) {
208 const detail = await response.text().catch(() => "")
209 throw new Error(`xAI device code request failed (${response.status})${detail ? `: ${detail}` : ""}`)
210 }
211 const json = (await response.json()) as DeviceCodeResponse
212 if (!json.device_code || !json.user_code || !json.verification_uri) {
213 throw new Error("xAI device code response is missing device_code / user_code / verification_uri")
214 }
215 return json
216}
217
218// Default sleep used between device-code polls. Test-injectable so we can
219// exercise authorization_pending / slow_down branches without real waits.

Callers 2

xai.test.tsFile · 0.90
XaiAuthPluginFunction · 0.85

Calls 4

fetchFunction · 0.70
authHeadersFunction · 0.70
textMethod · 0.65
jsonMethod · 0.65

Tested by

no test coverage detected