-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
do not block on CodyLLMSiteConfiguration (configOverwrites) fetch in …
…initial auth To authenticate a user and start showing the UI, we actually don't need to fetch the CodyLLMSiteConfiguration (`configOverwrites`). This reduces the number of HTTP requests (albeit they were parallelized somewhat) needed before the user can be authenticated and start seeing the Cody UI. This uncovered some possible "bugs" in the `anthropic.test.ts` autocomplete tests, where they were asserting that the `model` would be set but it actually would not be in real life. In `Provider.maybeFilterOutModel` it sees that `this.configOverwrites?.provider === 'sourcegraph'` in the test, but that should not be true in real life because it’s being passed an `authStatus` that is non-dotcom. The reason the test is bad is because that method gets the auth status from `currentAuthStatus()`, which is dotcom in testing only because of a prior test's mock value.
- Loading branch information
Showing
26 changed files
with
315 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Observable, map } from 'observable-fns' | ||
import { authStatus } from '../auth/authStatus' | ||
import { logError } from '../logger' | ||
import { distinctUntilChanged, pick, promiseFactoryToObservable } from '../misc/observable' | ||
import { pendingOperation, switchMapReplayOperation } from '../misc/observableOperation' | ||
import { type CodyLLMSiteConfiguration, graphqlClient } from '../sourcegraph-api/graphql/client' | ||
import { isError } from '../utils' | ||
|
||
/** | ||
* Observe the model-related config overwrites on the server for the currently authenticated user. | ||
*/ | ||
export const configOverwrites: Observable<CodyLLMSiteConfiguration | null | typeof pendingOperation> = | ||
authStatus.pipe( | ||
pick('authenticated', 'endpoint', 'pendingValidation'), | ||
distinctUntilChanged(), | ||
switchMapReplayOperation( | ||
( | ||
authStatus | ||
): Observable<CodyLLMSiteConfiguration | Error | null | typeof pendingOperation> => { | ||
if (authStatus.pendingValidation) { | ||
return Observable.of(pendingOperation) | ||
} | ||
|
||
if (!authStatus.authenticated) { | ||
return Observable.of(null) | ||
} | ||
|
||
return promiseFactoryToObservable(signal => | ||
graphqlClient.getCodyLLMConfiguration(signal) | ||
).pipe( | ||
map((result): CodyLLMSiteConfiguration | null | typeof pendingOperation => { | ||
if (isError(result)) { | ||
logError( | ||
'configOverwrites', | ||
`Failed to get Cody LLM configuration from ${authStatus.endpoint}: ${result}` | ||
) | ||
return null | ||
} | ||
return result ?? null | ||
}) | ||
) | ||
} | ||
), | ||
map(result => (isError(result) ? null : result)) // the operation catches its own errors, so errors will never get here | ||
) | ||
|
||
// Subscribe so that other subscribers get the replayed value. There are no other permanent | ||
// subscribers to this value. | ||
// | ||
// TODO(sqs): This fixes an issue where switching accounts (`rtx exec node@18.17.1 -- pnpm run test | ||
// agent/src/auth.test.ts -t 'switches'`) took ~2.7s on Node 18. | ||
configOverwrites.subscribe({}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.