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

Function loop

packages/core/src/plugin/provider/opencode.ts:240–260  ·  view source on GitHub ↗
(wait: Duration.Duration)

Source from the content-addressed store, hash-verified

238
239function poll(http: HttpClient.HttpClient, server: string, deviceCode: string, interval: Duration.Duration) {
240 const loop = (wait: Duration.Duration): Effect.Effect<Credential.OAuth, unknown> =>
241 Effect.gen(function* () {
242 yield* Effect.sleep(wait)
243 const result = yield* post(
244 http,
245 `${server}/auth/device/token`,
246 {
247 grant_type: "urn:ietf:params:oauth:grant-type:device_code",
248 device_code: deviceCode,
249 client_id: clientID,
250 },
251 DeviceToken,
252 false,
253 )
254 if ("access_token" in result) return yield* credential(http, server, result)
255 if (result.error === "authorization_pending") return yield* loop(wait)
256 if (result.error === "slow_down") {
257 return yield* loop(Duration.sum(wait, Duration.seconds(5)))
258 }
259 return yield* Effect.fail(new Error(`Device authorization failed: ${result.error}`))
260 })
261 return loop(interval)
262}
263

Callers 1

pollFunction · 0.70

Calls 2

postFunction · 0.70
credentialFunction · 0.70

Tested by

no test coverage detected