Path: blob/main/src/vs/workbench/contrib/chat/browser/viewsWelcome/chatViewsWelcomeHandler.ts
4780 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { MarkdownString } from '../../../../../base/common/htmlContent.js';6import { IJSONSchema, TypeFromJsonSchema } from '../../../../../base/common/jsonSchema.js';7import { ThemeIcon } from '../../../../../base/common/themables.js';8import { localize } from '../../../../../nls.js';9import { ContextKeyExpr } from '../../../../../platform/contextkey/common/contextkey.js';10import { ILogService } from '../../../../../platform/log/common/log.js';11import { Registry } from '../../../../../platform/registry/common/platform.js';12import { IWorkbenchContribution } from '../../../../common/contributions.js';13import { checkProposedApiEnabled } from '../../../../services/extensions/common/extensions.js';14import * as extensionsRegistry from '../../../../services/extensions/common/extensionsRegistry.js';15import { ChatViewsWelcomeExtensions, IChatViewsWelcomeContributionRegistry, IChatViewsWelcomeDescriptor } from './chatViewsWelcome.js';161718const chatViewsWelcomeJsonSchema = {19type: 'object',20additionalProperties: false,21required: ['icon', 'title', 'contents', 'when'],22properties: {23icon: {24type: 'string',25description: localize('chatViewsWelcome.icon', 'The icon for the welcome message.'),26},27title: {28type: 'string',29description: localize('chatViewsWelcome.title', 'The title of the welcome message.'),30},31content: {32type: 'string',33description: localize('chatViewsWelcome.content', 'The content of the welcome message. The first command link will be rendered as a button.'),34},35when: {36type: 'string',37description: localize('chatViewsWelcome.when', 'Condition when the welcome message is shown.'),38}39}40} as const satisfies IJSONSchema;4142type IRawChatViewsWelcomeContribution = TypeFromJsonSchema<typeof chatViewsWelcomeJsonSchema>;4344const chatViewsWelcomeExtensionPoint = extensionsRegistry.ExtensionsRegistry.registerExtensionPoint<IRawChatViewsWelcomeContribution[]>({45extensionPoint: 'chatViewsWelcome',46jsonSchema: {47description: localize('vscode.extension.contributes.chatViewsWelcome', 'Contributes a welcome message to a chat view'),48type: 'array',49items: chatViewsWelcomeJsonSchema,50},51});5253export class ChatViewsWelcomeHandler implements IWorkbenchContribution {5455static readonly ID = 'workbench.contrib.chatViewsWelcomeHandler';5657constructor(58@ILogService private readonly logService: ILogService,59) {60chatViewsWelcomeExtensionPoint.setHandler((extensions, delta) => {61for (const extension of delta.added) {62for (const providerDescriptor of extension.value) {63checkProposedApiEnabled(extension.description, 'chatParticipantPrivate');6465const when = ContextKeyExpr.deserialize(providerDescriptor.when);66if (!when) {67this.logService.error(`Could not deserialize 'when' clause for chatViewsWelcome contribution: ${providerDescriptor.when}`);68continue;69}7071const descriptor: IChatViewsWelcomeDescriptor = {72...providerDescriptor,73when,74icon: ThemeIcon.fromString(providerDescriptor.icon),75content: new MarkdownString(providerDescriptor.content, { isTrusted: true }), // private API with command links76};77Registry.as<IChatViewsWelcomeContributionRegistry>(ChatViewsWelcomeExtensions.ChatViewsWelcomeRegistry).register(descriptor);78}79}80});81}82}838485