codex-copilot-dx 0.4.37 → 0.4.39
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.
- package/bin/cli.mjs +4 -1
- package/package.json +1 -1
- package/src/copilot.mjs +17 -5
- package/src/startup.mjs +3 -7
package/bin/cli.mjs
CHANGED
|
@@ -132,7 +132,10 @@ async function refreshClaudeDesktopModelDefs() {
|
|
|
132
132
|
return modelDefs;
|
|
133
133
|
} catch (e) {
|
|
134
134
|
const fallback = MODEL_REGISTRY.modelDefs?.length ? `${MODEL_REGISTRY.source} model list` : "built-in model list";
|
|
135
|
-
|
|
135
|
+
const message = ctrl.signal.aborted
|
|
136
|
+
? `Model refresh timed out after ${MODEL_REFRESH_TIMEOUT_MS}ms; using ${fallback}`
|
|
137
|
+
: `Could not refresh model list; using ${fallback} (${e.message})`;
|
|
138
|
+
console.log(status("warn", message));
|
|
136
139
|
return MODEL_REGISTRY.modelDefs;
|
|
137
140
|
} finally {
|
|
138
141
|
clearTimeout(timer);
|
package/package.json
CHANGED
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
|
|
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, {
|
|
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({
|
|
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)) {
|
package/src/startup.mjs
CHANGED
|
@@ -2,16 +2,12 @@ export async function initializeModelRegistry({
|
|
|
2
2
|
loadCached,
|
|
3
3
|
currentModelDefs,
|
|
4
4
|
refresh,
|
|
5
|
-
onBackgroundError = () => {},
|
|
6
5
|
}) {
|
|
7
|
-
if (
|
|
8
|
-
return { modelDefs:
|
|
6
|
+
if (loadCached()) {
|
|
7
|
+
return { modelDefs: currentModelDefs(), source: "cache", backgroundRefresh: null };
|
|
9
8
|
}
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
.then(refresh)
|
|
13
|
-
.catch(onBackgroundError);
|
|
14
|
-
return { modelDefs: currentModelDefs(), source: "cache", backgroundRefresh };
|
|
10
|
+
return { modelDefs: await refresh(), source: "live", backgroundRefresh: null };
|
|
15
11
|
}
|
|
16
12
|
|
|
17
13
|
export function runInBackground(task, onError = () => {}) {
|