codex-copilot-dx 0.4.37 → 0.4.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/copilot.mjs +17 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codex-copilot-dx",
3
- "version": "0.4.37",
3
+ "version": "0.4.38",
4
4
  "description": "Use Codex Desktop, Claude Code, and Claude App with GitHub Copilot",
5
5
  "author": "Dale Xiao",
6
6
  "type": "module",
package/src/copilot.mjs CHANGED
@@ -323,11 +323,11 @@ function getGithubToken({ home = os.homedir() } = {}) {
323
323
  return token;
324
324
  }
325
325
 
326
- function requestCopilotToken(ghToken, { fetchImpl = fetch, signal } = {}) {
327
- return fetchImpl(`${GITHUB_API}/copilot_internal/v2/token`, {
326
+ function requestCopilotToken(ghToken, { fetchImpl = fetch, signal, retryOptions } = {}) {
327
+ return fetchCopilotUpstream(`${GITHUB_API}/copilot_internal/v2/token`, {
328
328
  headers: { Authorization: `token ${ghToken}`, Accept: "application/json" },
329
329
  signal,
330
- });
330
+ }, { fetchImpl, ...retryOptions });
331
331
  }
332
332
 
333
333
  function cacheCopilotTokenData(data, {
@@ -381,12 +381,17 @@ async function refreshCopilotToken({
381
381
  home = os.homedir(),
382
382
  env = process.env,
383
383
  fetchImpl = fetch,
384
+ tokenRetryOptions,
384
385
  } = {}) {
385
386
  const ghToken = getGithubToken({ home });
386
387
  const sourceKey = githubTokenPath(home);
387
388
  let resp;
388
389
  try {
389
- resp = await requestCopilotToken(ghToken, { fetchImpl, signal });
390
+ resp = await requestCopilotToken(ghToken, {
391
+ fetchImpl,
392
+ signal,
393
+ retryOptions: tokenRetryOptions,
394
+ });
390
395
  } catch (e) {
391
396
  if (!isAbortError(e, signal)) e.transient = true;
392
397
  throw e;
@@ -454,8 +459,15 @@ export function getCopilotToken(options = {}) {
454
459
 
455
460
  if (!flight) {
456
461
  const controller = new AbortController();
462
+ const tokenRetryOptions = options.tokenRetryOptions
463
+ ?? (canUseCachedToken(sourceKey, now, allowCurrentProcessToken) ? { retries: 0 } : undefined);
457
464
  flight = { key: sourceKey, controller, waiters: 0, settled: false, promise: null };
458
- flight.promise = refreshCopilotToken({ ...options, home, signal: controller.signal })
465
+ flight.promise = refreshCopilotToken({
466
+ ...options,
467
+ home,
468
+ signal: controller.signal,
469
+ tokenRetryOptions,
470
+ })
459
471
  .catch((error) => {
460
472
  const fallbackNow = Date.now();
461
473
  if (error?.transient && canUseCachedToken(sourceKey, fallbackNow)) {