UNPKG

@ckeditor/ckeditor5-ai

Version:

AI features for CKEditor 5.

230 lines (229 loc) • 7.71 kB
/** * @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options */ /** * @module ai/aiquickactions/aiquickactions * @publicApi */ import { type Editor, Plugin } from 'ckeditor5/src/core.js'; import { AIQuickActionsUI, type AIQuickActionDefinition } from './aiquickactionsui.js'; import { AIQuickActionsEditing } from './aiquickactionsediting.js'; import { AIActions } from '../aiactions/aiactions.js'; /** * The AI Quick Actions feature. * * Quick Actions streamline routine content transformations by offering one-click AI-powered suggestions directly within the editor. * You can also ask questions about your selected text in the Chat to get instant AI insights and analysis. * * You can configure the feature by setting the {@link module:ai/aiquickactions/aiquickactions~AIQuickActionsConfig} property. * * Learn more about AI features in CKEditor in the {@glink features/ai/ckeditor-ai-overview AI Overview} documentation. */ export declare class AIQuickActions extends Plugin { /** * @inheritDoc */ static get requires(): readonly [typeof AIQuickActionsUI, typeof AIQuickActionsEditing, typeof AIActions]; /** * @inheritDoc */ static get pluginName(): "AIQuickActions"; /** * @inheritDoc */ static get isOfficialPlugin(): true; /** * @inheritDoc */ static get isPremiumPlugin(): true; constructor(editor: Editor); } /** * The configuration of the {@link module:ai/aiquickactions/aiquickactions~AIQuickActions AI Quick Actions feature}. * * The properties defined in this config are set in the `config.ai.quickActions` namespace. * * ```ts * ClassicEditor * .create( editorElement, { * ai: { * quickActions: { * // AI Quick Actions configuration. * } * } * } ) * .then( ... ) * .catch( ... ); * ``` * * See {@link module:ai/aiconfig~AIConfig the full AI configuration}. * * See {@link module:core/editor/editorconfig~EditorConfig all editor options}. */ export interface AIQuickActionsConfig { /** * The extra commands to add to the AI Quick Actions feature to become available for the user. You can fine-tune * the commands by specifying the type, prompt, and other properties. By default, the extra commands land in the * "Other" group in the user interface. * * The following example will add three new commands to the AI Quick Actions feature: * * ```ts * ClassicEditor * .create( editorElement, { * // ... Other configuration options ... * ai: { * quickActions: { * extraCommands: [ * // An action that requires content to be selected in the editor (it transforms the selected content). * { id: 'add-quote-from-famous-person', displayedPrompt: 'Add a quote from a famous person', prompt: 'Add a quote from a known person, which would make sense in the context of the selected text.', type: AIQuickActionType.ACTION, model: 'claude-4-sonnet' }, { id: 'summarize-in-bullet-points', displayedPrompt: 'Summarize in 5 bullet points', prompt: 'Summarize the selected text in 5 bullet points.', type: AIQuickActionType.CHAT }, { id: 'include-more-sarcasm', displayedPrompt: 'Rewrite adding more sarcasm', prompt: 'Rewrite using a sarcastic tone.', type: AIQuickActionType.ACTION, model: 'claude-4-sonnet' } * * // ... More commands ... * ], * }, * } * } ) * .then( ... ) * .catch( ... ); * ``` */ extraCommands?: Array<AICustomQuickActionDefinition>; /** * The ids of the commands to remove from the AI Quick Actions feature. Removing all commands from a specific category * will remove the category from the user interface. * * The defaults are as follows: * * - `'ask-ai`, * - "Chat commands" category * - `'explain'`, * - `'summarize'`, * - `'highlight-key-points'`, * - `'improve-writing'`, * - `'continue'`, * - `'fix-grammar'`, * - "Adjust length" category * - `'make-shorter'`, * - `'make-longer'`, * - "Change tone" category * - `'make-tone-casual'`, * - `'make-tone-direct'`, * - `'make-tone-friendly'`, * - `'make-tone-confident'`, * - `'make-tone-professional'`, * - "Translate" category * - `'translate-to-english'`, * - `'translate-to-chinese'`, * - `'translate-to-french'`, * - `'translate-to-german'`, * - `'translate-to-italian'`, * - `'translate-to-portuguese'`, * - `'translate-to-russian'` * * The following example will remove the "Explain" and "Summarize" commands from the user interface: * * ```ts * ClassicEditor * .create( editorElement, { * // ... Other configuration options ... * ai: { * quickActions: { * removeCommands: [ * 'explain', * 'summarize', * // ... * ] * }, * } * } ) * .then( ... ) * .catch( ... ); * ``` */ removeCommands?: Array<string>; /** * Whether to enable search functionality in the AI Quick Actions dropdown. * * When enabled, users can search through available quick actions using a search input field. * When disabled, the search input is hidden and all actions are displayed in a list. * * @default true * * ```ts * ClassicEditor * .create( editorElement, { * // ... Other configuration options ... * ai: { * quickActions: { * isSearchEnabled: false * } * } * } ) * .then( ... ) * .catch( ... ); * ``` */ isSearchEnabled?: boolean; } /** * Defines a custom AI quick action with all required properties. * * An example of an action that requires content to be selected in the editor (it transforms the selected content): * * ```ts *{ * id: 'add-quote-from-famous-person', * displayedPrompt: 'Add a quote from a famous person', * prompt: 'Add a quote from a known person, which would make sense in the context of the selected text.', * type: AIQuickActionType.ACTION, * model: 'claude-4-sonnet' *} * ``` * * An example of an action that does not require content to be selected in the editor (adds a new content): * * ```ts * { * id: 'add-random-cat-fact', * displayedPrompt: 'Add cat fact.', * prompt: 'Add a random fact about cats to the document.', * type: 'ACTION', * requiresContent: false * } * ``` * * An example of an action that opens the {@link module:ai/aichat/aichat~AIChat AI Chat} interface for interactive conversations: * * ```ts * { * id: 'summarize-in-bullet-points', * displayedPrompt: 'Summarize in 5 bullet points', * prompt: 'Summarize the selected text in 5 bullet points.', * type: AIQuickActionType.CHAT *} * ``` */ export type AICustomQuickActionDefinition = Required<Pick<AIQuickActionDefinition, 'id' | 'displayedPrompt' | 'prompt' | 'type' | 'model'>> & { requiresContent?: boolean; }; export type AIQuickActionRequestData = Pick<AIQuickActionDefinition, 'id' | 'displayedPrompt'>;