Skip to content

Commit 0f9f956

Browse files
committed
perf(infra): skip usage auth discovery on default path
1 parent 4f73cd2 commit 0f9f956

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

src/infra/provider-usage.auth.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,14 +367,35 @@ export async function resolveProviderAuths(params: {
367367
env: params.env ?? process.env,
368368
agentDir: params.agentDir,
369369
};
370-
const hasAuthProfileStoreSource = hasAnyAuthProfileStoreSource(params.agentDir);
371370
const authProfileSourceState: UsageAuthState = {
372371
...stateBase,
373372
allowAuthProfileStore: true,
374373
};
374+
const hasAuthProfileStoreSource = params.skipPluginAuthWithoutCredentialSource
375+
? hasAnyAuthProfileStoreSource(params.agentDir)
376+
: false;
375377
const auths: ProviderAuth[] = [];
376378

377379
for (const provider of params.providers) {
380+
if (!params.skipPluginAuthWithoutCredentialSource) {
381+
const pluginAuth = await resolveProviderUsageAuthViaPlugin({
382+
state: authProfileSourceState,
383+
provider,
384+
});
385+
if (pluginAuth) {
386+
auths.push(pluginAuth);
387+
continue;
388+
}
389+
const fallbackAuth = await resolveProviderUsageAuthFallback({
390+
state: authProfileSourceState,
391+
provider,
392+
});
393+
if (fallbackAuth) {
394+
auths.push(fallbackAuth);
395+
}
396+
continue;
397+
}
398+
378399
const directCredentialState = { ...stateBase, allowAuthProfileStore: false };
379400
const credentialProviderIds = resolveUsageCredentialProviderIds({
380401
state: directCredentialState,
@@ -392,7 +413,6 @@ export async function resolveProviderAuths(params: {
392413
providerIds: credentialProviderIds,
393414
});
394415
const allowAuthProfileStore =
395-
!params.skipPluginAuthWithoutCredentialSource ||
396416
hasDirectCredentialSource ||
397417
(hasAuthProfileStoreSource &&
398418
hasAuthProfileCredentialSource({
@@ -409,7 +429,7 @@ export async function resolveProviderAuths(params: {
409429
const hasPluginCredentialSource =
410430
hasDirectCredentialSource || allowAuthProfileStore || hasLegacyPiAgentCredentialSource;
411431

412-
if (!params.skipPluginAuthWithoutCredentialSource || hasPluginCredentialSource) {
432+
if (hasPluginCredentialSource) {
413433
const pluginAuth = await resolveProviderUsageAuthViaPlugin({
414434
state,
415435
provider,

0 commit comments

Comments
 (0)