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

Improve model access dialog messaging #212974

Merged
merged 1 commit into from
May 17, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions src/vs/workbench/api/browser/mainThreadAuthentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { Disposable, DisposableMap } from 'vs/base/common/lifecycle';
import * as nls from 'vs/nls';
import { extHostNamedCustomer, IExtHostContext } from 'vs/workbench/services/extensions/common/extHostCustomers';
import { IAuthenticationCreateSessionOptions, AuthenticationSession, AuthenticationSessionsChangeEvent, IAuthenticationProvider, IAuthenticationService, IAuthenticationExtensionsService } from 'vs/workbench/services/authentication/common/authentication';
import { IAuthenticationCreateSessionOptions, AuthenticationSession, AuthenticationSessionsChangeEvent, IAuthenticationProvider, IAuthenticationService, IAuthenticationExtensionsService, INTERNAL_AUTH_PROVIDER_PREFIX as INTERNAL_MODEL_AUTH_PROVIDER_PREFIX } from 'vs/workbench/services/authentication/common/authentication';
import { ExtHostAuthenticationShape, ExtHostContext, MainContext, MainThreadAuthenticationShape } from '../common/extHost.protocol';
import { IDialogService, IPromptButton } from 'vs/platform/dialogs/common/dialogs';
import Severity from 'vs/base/common/severity';
Expand Down Expand Up @@ -117,10 +117,17 @@ export class MainThreadAuthentication extends Disposable implements MainThreadAu
$removeSession(providerId: string, sessionId: string): Promise<void> {
return this.authenticationService.removeSession(providerId, sessionId);
}
private async loginPrompt(providerName: string, extensionName: string, recreatingSession: boolean, options?: AuthenticationForceNewSessionOptions): Promise<boolean> {
const message = recreatingSession
? nls.localize('confirmRelogin', "The extension '{0}' wants you to sign in again using {1}.", extensionName, providerName)
: nls.localize('confirmLogin', "The extension '{0}' wants to sign in using {1}.", extensionName, providerName);
private async loginPrompt(provider: IAuthenticationProvider, extensionName: string, recreatingSession: boolean, options?: AuthenticationForceNewSessionOptions): Promise<boolean> {
let message: string;

// An internal provider is a special case which is for model access only.
if (provider.id.startsWith(INTERNAL_MODEL_AUTH_PROVIDER_PREFIX)) {
message = nls.localize('confirmModelAccess', "The extension '{0}' wants to access the language models provided by {1}.", extensionName, provider.label);
} else {
message = recreatingSession
? nls.localize('confirmRelogin', "The extension '{0}' wants you to sign in again using {1}.", extensionName, provider.label)
: nls.localize('confirmLogin', "The extension '{0}' wants to sign in using {1}.", extensionName, provider.label);
}

const buttons: IPromptButton<boolean | undefined>[] = [
{
Expand All @@ -134,7 +141,7 @@ export class MainThreadAuthentication extends Disposable implements MainThreadAu
buttons.push({
label: nls.localize('learnMore', "Learn more"),
run: async () => {
const result = this.loginPrompt(providerName, extensionName, recreatingSession, options);
const result = this.loginPrompt(provider, extensionName, recreatingSession, options);
await this.openerService.open(URI.revive(options.learnMore!), { allowCommands: true });
return await result;
}
Expand Down Expand Up @@ -199,7 +206,7 @@ export class MainThreadAuthentication extends Disposable implements MainThreadAu
// We only want to show the "recreating session" prompt if we are using forceNewSession & there are sessions
// that we will be "forcing through".
const recreatingSession = !!(options.forceNewSession && sessions.length);
const isAllowed = await this.loginPrompt(provider.label, extensionName, recreatingSession, uiOptions);
const isAllowed = await this.loginPrompt(provider, extensionName, recreatingSession, uiOptions);
if (!isAllowed) {
throw new Error('User did not consent to login.');
}
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/api/common/extHostLanguageModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,8 @@ export class ExtHostLanguageModels implements ExtHostLanguageModelsShape {

try {
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);
? localize('chatAccessWithJustification', "Justification: {1}", to.displayName, justification)
: undefined;
await this._extHostAuthentication.getSession(from, providerId, [], { forceNewSession: { detail } });
this.$updateModelAccesslist([{ from: from.identifier, to: to.identifier, enabled: true }]);
return true;
Expand Down
Loading