/** * @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/aiactions/aiactions * @publicApi */ import { type Editor, Plugin, type PluginDependenciesOf } from "@ckeditor/ckeditor5-core"; import { AIConnector } from "../aicore/aiconnector.js"; import { AIErrorSink } from "../aicore/aierrorreporter.js"; import { Dialog } from "@ckeditor/ckeditor5-ui"; import { AIEditing } from "../aicore/aiediting.js"; import { type AIContextRef } from "../aicore/model/aicontextref.js"; import { AIBalloon } from "../aiballoon/aiballoon.js"; import { DocumentChanges } from "../aisdk/documentchanges.js"; /** * @experimental **Experimental:** Some methods of this class are production-ready but experimental and may change * in minor releases without the standard deprecation policy. Check the changelog for migration guidance. */ export declare class AIActions extends Plugin { /** * @inheritDoc */ static get requires(): PluginDependenciesOf<[AIConnector, AIErrorSink, Dialog, AIEditing, AIBalloon, DocumentChanges]>; /** * @inheritDoc */ static get pluginName(): "AIActions"; /** * @inheritDoc */ static override get isOfficialPlugin(): true; /** * @inheritDoc */ static override get isPremiumPlugin(): true; /** * The busy state of the AI actions. * * It is set to `true` when there are AI response being streamed or rendered. * * @observable */ isBusy: boolean; constructor(editor: Editor); /** * Stops the currently running AI action interaction, aborting any in-progress streaming and resetting the busy state. * * @experimental **Experimental:** This is a production-ready API but may change in minor releases * without the standard deprecation policy. Check the changelog for migration guidance. */ stopInteraction(): void; /** * Executes an AI action on the current editor selection. The action processes the selected content * using the AI model and displays the result in an inline balloon. * * @experimental **Experimental:** This is a production-ready API but may change in minor releases * without the standard deprecation policy. Check the changelog for migration guidance. * @param action The action definition specifying which AI action to execute. * @param label The display label shown in the balloon UI while the action is being processed. * @param icon Optional icon to display alongside the label in the balloon UI. */ executeAction(action: AIActionDefinition, label: string, icon?: string): Promise; /** * @inheritDoc */ override destroy(): Promise; private _createInteraction; } export type AIActionsNames = "continue" | "fix-grammar" | "improve-writing" | "make-longer" | "make-shorter" | "make-tone-casual" | "make-tone-formal" | "translate"; /** * Defines the parameters for an AI action executed via * {@link module:ai/aiactions/aiactions~AIActions#executeAction `executeAction()`}. * * The definition supports a few different shapes, depending on the action type and its prompt source: * * A system action runs one of the predefined actions. Provide its `actionName`. * * ```ts * { * actionName: 'improve-writing' * } * ``` * * A custom action runs an inline prompt. Provide the `model` together with a `userMessage` that carries the prompt. * * ```ts * { * model: 'claude-4-6-sonnet', * userMessage: 'Rewrite the selected text in a more formal tone.' * } * ``` * * A custom action can also rely on a context reference instead of an inline prompt. In that case neither `actionName` * nor `userMessage` is set, and the referenced context is passed through `contexts`. * * ```ts * { * model: 'claude-4-6-sonnet', * contexts: [ { id: 'style-guide', promptId: 'improve-writing' } ] * } * ``` */ export type AIActionDefinition = { actionName?: AIActionsNames; args?: Record; userMessage?: string; model?: string; /** * Context references attached to the action. * * @experimental **Experimental:** This is a production-ready API but may change in minor releases * without the standard deprecation policy. Check the changelog for migration guidance. */ contexts?: Array; };