@ckeditor/ckeditor5-ai
Version:
AI features for CKEditor 5.
317 lines (316 loc) • 11.1 kB
TypeScript
/**
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/
/**
* @module ai/aichatshortcuts/aichatshortcuts
* @publicApi
*/
import { AIChatUI } from '../aichat/aichatui.js';
import { ContextPlugin } from '@ckeditor/ckeditor5-core';
import '../../theme/aichatshortcuts/aichatshortcuts.css';
/**
* The type of the shortcut.
*
* Available types:
* * `'chat'`: a shortcut that interacts with AI Chat,
* * `'review'`: a shortcut that interacts with AI Review,
* * `'translate'`: a shortcut that interacts with AI Translate.
*/
export type AIChatShortcutType = 'chat' | 'review' | 'translate';
/**
* The plugin that displays a list of handy, configurable shortcuts in the {@link module:ai/aichat/aichat~AIChat AI Chat} feed
* upon opening a new conversation.
*
* Learn more about configuring AI Chat Shortcuts in {@link module:ai/aichat/aichat~AIChatConfig#shortcuts}.
*/
export declare class AIChatShortcuts extends ContextPlugin {
/**
* @inheritDoc
*/
static get requires(): readonly [typeof AIChatUI];
/**
* @inheritDoc
*/
static get pluginName(): "AIChatShortcuts";
/**
* @inheritDoc
*/
static get isOfficialPlugin(): true;
/**
* @inheritDoc
*/
static get isPremiumPlugin(): true;
/**
* @inheritDoc
*/
init(): void;
}
declare module '../aichat/aichat.js' {
interface AIChatConfig {
/**
* A list of shortcuts to be displayed in the AI Chat Shortcuts feed.
*
* ```ts
* ClassicEditor
* .create( {
* ai: {
* chat: {
* shortcuts: [
* // ...
* ]
* }
* }
* } )
* .then( ... )
* .catch( ... );
* ```
*/
shortcuts?: ReadonlyArray<AIChatShortcutDefinition>;
}
}
/**
* Represents all shortcut definition types:
*
* * {@link module:ai/aichatshortcuts/aichatshortcuts~AIChatShortcutChatDefinition Chat shortcuts},
* * {@link module:ai/aichatshortcuts/aichatshortcuts~AIChatShortcutReviewDefinition Review shortcuts},
* * {@link module:ai/aichatshortcuts/aichatshortcuts~AIChatShortcutTranslateDefinition Translate shortcuts}.
*/
export type AIChatShortcutDefinition = AIChatShortcutChatDefinition | AIChatShortcutReviewDefinition | AIChatShortcutTranslateDefinition;
/**
* The base definition for all shortcut types.
*/
export interface AIChatShortcutBaseDefinition {
/**
* The unique identifier of the shortcut.
*/
readonly id: string;
/**
* The human-readable label of the shortcut.
*/
readonly label: string;
/**
* The type of the shortcut.
*/
readonly type: AIChatShortcutType;
/**
* The icon of the shortcut in SVG string format.
*
* Learn more about setting the icon in the {@link module:ui/icon/iconview~IconView#content `IconView` API reference}.
*
* **Note**: When not provided, a generic icon associated with the shortcut type will be used instead.
*/
readonly icon?: string;
}
/**
* A shortcut that interacts with the AI Chat.
*
* Example of a shortcut that executes an AI Chat prompt with {@glink features/ai/ckeditor-ai-chat#reasoning Reasoning} and
* {@glink features/ai/ckeditor-ai-chat#web-search Web Search} features turned on:
* ```ts
* {
* id: 'continue-writing',
* type: 'chat',
* label: 'Continue writing',
* prompt: 'Continue writing this document. Match the existing tone, vocabulary level, and formatting. ' +
* 'Do not repeat or summarize earlier sections. Ensure logical flow and progression of ideas. ' +
* 'Add approximately 3 paragraphs.',
* useReasoning: true,
* useWebSearch: true
* }
* ```
*
* Example of a shortcut that runs in draft mode allowing the user to fine-tune the prompt before sending it:
* ```ts
* {
* id: 'rewrite-document',
* type: 'chat',
* label: 'Rewrite the document',
* prompt: `Rewrite the document below for the following audience:
*
* Audience: [e.g. Product / Engineering /Leadership]
* Primary concern: [e.g., escalations, integrations, customer sentiment]
* Context: [e.g. Internal performance review]
*
* Guidelines:
*
* - Emphasize sections most relevant to this audience
* - De-emphasize or condense less relevant details
* - Adjust terminology to match how this team thinks and speaks
* - Keep metrics accurate and unchanged
*
* Tone: [e.g. Clear, practical, collaborative]`,
* useReasoning: true,
* draftMode: true
* },
* ```
*/
export interface AIChatShortcutChatDefinition extends AIChatShortcutBaseDefinition {
type: 'chat';
/**
* The prompt to be sent to the AI Chat.
*/
readonly prompt: string;
/**
* When enabled, the shortcut will use draft mode, which means that the prompt will
* not be submitted immediately, instead the AI Chat input will be filled with the shortcut prompt.
* This gives the user ability to fine-tune the prompt, or fill in missing data, before sending it to the AI Chat.
*
* @default false
*/
readonly draftMode?: boolean;
/**
* When enabled, the shortcut will run in web search mode, which means the AI Chat will access
* and retrieve real-time information from the internet.
*
* See the {@glink features/ai/ckeditor-ai-integration#supported-ai-models integration guide} to learn more about models
* supporting web search.
*
* @default false
*/
readonly useWebSearch?: boolean;
/**
* When enabled, the shortcut will run in reasoning mode, which means the AI Chat will use the
* ability to think through problems, draw logical conclusions, and make sense of complex information.
*
* See the {@glink features/ai/ckeditor-ai-integration#supported-ai-models integration guide} to learn more about models
* supporting reasoning.
*
* @default false
*/
readonly useReasoning?: boolean;
/**
* The ID of the model to be used for the AI Chat shortcut.
*
* See the {@glink features/ai/ckeditor-ai-integration#supported-ai-models integration guide} to learn more about
* available models.
*
* **Note**: The used ID must be enabled in the
* {@link module:ai/aicore/model/aimodels~AIModelsConfig#displayedModels `config.ai.models.displayedModels`}.
*
* **Note**: When not provided, the default model will be used. See
* {@link module:ai/aicore/model/aimodels~AIModelsConfig#defaultModelId `config.ai.models.defaultModelId`} to learn more.
*/
readonly model?: string;
}
/**
* A shortcut that interacts with the AI Review.
*
* **Note**: This shortcut type requires the {@link module:ai/aireviewmode/aireviewmode~AIReviewMode `AIReviewMode`} plugin to be loaded.
*
* This type of shortcut can run both predefined and extra review commands. The list of predefined review commands with available parameters
* can be found in the {@glink features/ai/ckeditor-ai-review#review-commands AI Review documentation}. Extra review commands are defined
* via the {@link module:ai/aireviewmode/aireviewmode~AIReviewModeConfig#extraCommands `config.ai.review.extraCommands`} configuration.
*
* Example of a shortcut that opens the AI Review mode:
* ```ts
* {
* id: 'open-review',
* label: 'Open review',
* type: 'review'
* }
* ```
*
* Example of a shortcut that runs the `'correctness'` review command:
* ```ts
* {
* id: 'check-correctness',
* label: 'Proofread this document',
* type: 'review',
* commandId: 'correctness'
* }
* ```
*
* Example of a shortcut that runs the `'tone'` review command with a parameter:
* ```ts
* {
* id: 'adjust-tone',
* label: 'Change the tone of this document to casual',
* type: 'review',
* commandId: 'tone',
* params: [ 'casual' ]
* }
* ```
*
* Example of a shortcut that runs the `'custom'` review command with a specific model and a prompt:
* ```ts
* {
* id: 'custom-review',
* label: 'Custom grammar command using the gpt-5.1 model',
* type: 'review',
* commandId: 'custom',
* model: 'gpt-5.1',
* prompt: 'Check grammar and style.'
* }
* ```
*/
export interface AIChatShortcutReviewDefinition extends AIChatShortcutBaseDefinition {
type: 'review';
/**
* The ID of the review command to be run.
*
* **Note**: When not provided, the shortcut will switch the user interface to the AI Review.
*
* See {@link module:ai/aireviewmode/aireviewmode~AIReviewModeConfig#availableCommands `config.ai.review.availableCommands`}
* for the list of available review commands.
*/
readonly commandId?: string;
/**
* The ID of the model to be used for the `'custom'` review command that requires a model identifier.
*
* See the {@glink features/ai/ckeditor-ai-integration#supported-ai-models integration guide} to learn more about
* available models.
*
* **Note**: When not provided, the default model will be used instead. See
* {@link module:ai/aicore/model/aimodels~AIModelsConfig#defaultModelId `config.ai.models.defaultModelId`} to learn more.
*/
readonly model?: string;
/**
* The prompt to be sent to the AI Review for the `'custom'` review command that requires a prompt.
*/
readonly prompt?: string;
/**
* The parameters to be used for review commands that require parameters (e.g. `'length'`, `'tone'`, etc.).
*/
readonly params?: Array<string>;
}
/**
* A shortcut that interacts with the AI Translate.
*
* **Note**: This shortcut type requires the {@link module:ai/aitranslate/aitranslate~AITranslate `AITranslate`} plugin to be loaded.
*
* This type of shortcut can run the translation with any of the available languages. It can be
* {@glink features/ai/ckeditor-ai-translate#languages-list one of the languages available by default},
* or a custom language defined by the integrator via the
* {@link module:ai/aitranslate/aitranslate~AITranslateConfig#languages `config.ai.translate.languages`} configuration option.
*
* Example of a shortcut that opens the AI Translate mode:
* ```ts
* {
* id: 'open-translate',
* label: 'Open translate',
* type: 'translate'
* }
* ```
*
* Example of a shortcut that runs the translation to Spanish:
* ```ts
* {
* id: 'translate-to-spanish',
* label: 'Translate this document to Spanish',
* type: 'translate',
* language: 'spanish'
* }
* ```
*/
export interface AIChatShortcutTranslateDefinition extends AIChatShortcutBaseDefinition {
type: 'translate';
/**
* The language to be used for the translation.
*
* See {@link module:ai/aitranslate/aitranslate~AITranslateConfig#languages} for the list of supported languages.
*
* **Note**: When not provided, the shortcut will switch the user interface to the AI Translate.
*/
readonly language?: string;
}