Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Couple LanguageModel auth fixes #205233

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 5 additions & 8 deletions src/vs/workbench/api/browser/mainThreadChatProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,16 @@ export class MainThreadChatProvider implements MainThreadChatProviderShape {
return Disposable.None;
}

const accountLabel = auth.accountLabel ?? localize('languageModelsAccountId', 'Language Models');
const disposables = new DisposableStore();
this._authenticationService.registerAuthenticationProvider(authProviderId, new LanguageModelAccessAuthProvider(authProviderId, auth.providerLabel, auth.accountLabel));
this._authenticationService.registerAuthenticationProvider(authProviderId, new LanguageModelAccessAuthProvider(authProviderId, auth.providerLabel, accountLabel));
disposables.add(toDisposable(() => {
this._authenticationService.unregisterAuthenticationProvider(authProviderId);
}));
disposables.add(this._authenticationService.onDidChangeSessions(async (e) => {
if (e.providerId === authProviderId) {
if (e.event.removed?.length) {
const allowedExtensions = this._authenticationService.readAllowedExtensions(authProviderId, authProviderId);
const allowedExtensions = this._authenticationService.readAllowedExtensions(authProviderId, accountLabel);
const extensionsToUpdateAccess = [];
for (const allowed of allowedExtensions) {
const from = await this._extensionService.getExtension(allowed.id);
Expand All @@ -146,7 +147,7 @@ export class MainThreadChatProvider implements MainThreadChatProviderShape {
}
}));
disposables.add(this._authenticationService.onDidChangeExtensionSessionAccess(async (e) => {
const allowedExtensions = this._authenticationService.readAllowedExtensions(authProviderId, authProviderId);
const allowedExtensions = this._authenticationService.readAllowedExtensions(authProviderId, accountLabel);
const accessList = [];
for (const allowedExtension of allowedExtensions) {
const from = await this._extensionService.getExtension(allowedExtension.id);
Expand Down Expand Up @@ -174,11 +175,7 @@ class LanguageModelAccessAuthProvider implements IAuthenticationProvider {

private _session: AuthenticationSession | undefined;

constructor(
readonly id: string,
readonly label: string,
private readonly _accountLabel: string = localize('languageModelsAccountId', 'Language Models')
) { }
constructor(readonly id: string, readonly label: string, private readonly _accountLabel: string) { }

async getSessions(scopes?: string[] | undefined): Promise<readonly AuthenticationSession[]> {
// If there are no scopes and no session that means no extension has requested a session yet
Expand Down
11 changes: 5 additions & 6 deletions src/vs/workbench/api/common/extHostChatProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,17 +266,16 @@ export class ExtHostChatProvider implements ExtHostChatProviderShape {
}

// BIG HACK: Using AuthenticationProviders to check access to Language Models
private async _getAuthAccess(from: IExtensionDescription, to: { identifier: ExtensionIdentifier; displayName: string }, detail?: string): Promise<void> {
private async _getAuthAccess(from: IExtensionDescription, to: { identifier: ExtensionIdentifier; displayName: string }, justification?: string): Promise<void> {
// This needs to be done in both MainThread & ExtHost ChatProvider
const providerId = INTERNAL_AUTH_PROVIDER_PREFIX + to.identifier.value;
const session = await this._extHostAuthentication.getSession(from, providerId, [], { silent: true });
if (!session) {
try {
await this._extHostAuthentication.getSession(from, providerId, [], {
forceNewSession: {
detail: detail ?? localize('chatAccess', "To allow access to the language models provided by {0}", to.displayName),
}
});
const detail = justification
? localize('chatAccessWithJustification', "To allow access to the language models provided by {0}. Justification:\n\n{1}", to.displayName, justification)
: localize('chatAccess', "To allow access to the language models provided by {0}", to.displayName);
await this._extHostAuthentication.getSession(from, providerId, [], { forceNewSession: { detail } });
} catch (err) {
throw new Error('Access to language models has not been granted');
}
Expand Down