Skip to content

Commit e6a59ec

Browse files
Couple LanguageModel auth fixes (microsoft#205233)
1. use the accountLabel 2. always have our detail, and then add on a justification if provided
1 parent 0353033 commit e6a59ec

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

src/vs/workbench/api/browser/mainThreadChatProvider.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,16 @@ export class MainThreadChatProvider implements MainThreadChatProviderShape {
120120
return Disposable.None;
121121
}
122122

123+
const accountLabel = auth.accountLabel ?? localize('languageModelsAccountId', 'Language Models');
123124
const disposables = new DisposableStore();
124-
this._authenticationService.registerAuthenticationProvider(authProviderId, new LanguageModelAccessAuthProvider(authProviderId, auth.providerLabel, auth.accountLabel));
125+
this._authenticationService.registerAuthenticationProvider(authProviderId, new LanguageModelAccessAuthProvider(authProviderId, auth.providerLabel, accountLabel));
125126
disposables.add(toDisposable(() => {
126127
this._authenticationService.unregisterAuthenticationProvider(authProviderId);
127128
}));
128129
disposables.add(this._authenticationService.onDidChangeSessions(async (e) => {
129130
if (e.providerId === authProviderId) {
130131
if (e.event.removed?.length) {
131-
const allowedExtensions = this._authenticationService.readAllowedExtensions(authProviderId, authProviderId);
132+
const allowedExtensions = this._authenticationService.readAllowedExtensions(authProviderId, accountLabel);
132133
const extensionsToUpdateAccess = [];
133134
for (const allowed of allowedExtensions) {
134135
const from = await this._extensionService.getExtension(allowed.id);
@@ -146,7 +147,7 @@ export class MainThreadChatProvider implements MainThreadChatProviderShape {
146147
}
147148
}));
148149
disposables.add(this._authenticationService.onDidChangeExtensionSessionAccess(async (e) => {
149-
const allowedExtensions = this._authenticationService.readAllowedExtensions(authProviderId, authProviderId);
150+
const allowedExtensions = this._authenticationService.readAllowedExtensions(authProviderId, accountLabel);
150151
const accessList = [];
151152
for (const allowedExtension of allowedExtensions) {
152153
const from = await this._extensionService.getExtension(allowedExtension.id);
@@ -174,11 +175,7 @@ class LanguageModelAccessAuthProvider implements IAuthenticationProvider {
174175

175176
private _session: AuthenticationSession | undefined;
176177

177-
constructor(
178-
readonly id: string,
179-
readonly label: string,
180-
private readonly _accountLabel: string = localize('languageModelsAccountId', 'Language Models')
181-
) { }
178+
constructor(readonly id: string, readonly label: string, private readonly _accountLabel: string) { }
182179

183180
async getSessions(scopes?: string[] | undefined): Promise<readonly AuthenticationSession[]> {
184181
// If there are no scopes and no session that means no extension has requested a session yet

src/vs/workbench/api/common/extHostChatProvider.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -266,17 +266,16 @@ export class ExtHostChatProvider implements ExtHostChatProviderShape {
266266
}
267267

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

0 commit comments

Comments
 (0)