/** * @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/aicore/model/aidefaultcontext * @publicApi */ import { type AIContextRef } from "./aicontextref.js"; /** * Identifiers of the AI features that a {@link module:ai/aicore/model/aidefaultcontext~AIDefaultContextEntry * default context entry} can target. */ export type AIDefaultContextFeature = "chat" | "quickActions" | "review" | "translate"; /** * Narrows down which invocations of the AI features a * {@link module:ai/aicore/model/aidefaultcontext~AIDefaultContextEntry default context entry} applies to. * * Each key targets one AI feature. When a key is omitted, the entry is **not** applied to that feature. A value * of `true` applies the entry to every invocation of the feature, while a `RegExp` applies it only when one of * the invocation IDs matches: * * * `chat` - the ID of the {@link module:ai/aichatshortcuts/aichatshortcuts~AIChatShortcutChatDefinition chat shortcut} * used to start a conversation. A matching `RegExp` attaches the entry to that conversation, so it applies to the * shortcut's message **and** to the conversation's later messages. A conversation not started by a matching shortcut * (for example one started with a free-form message) receives the entry only when the value is `true`. * * `quickActions` - the ID of the quick action or of its group, * * `review` - the ID of the review command, * * `translate` - the ID of the target language. * * ```ts * // Attach to all review commands, but only to the translate quick actions. * { * review: true, * quickActions: /^translate/ * } * ``` */ export interface AIDefaultContextFeatures { /** * Whether the entry is attached to the AI Chat messages. Provide a `RegExp` to attach it when a conversation is * started with an {@link module:ai/aichatshortcuts/aichatshortcuts~AIChatShortcutChatDefinition AI Chat shortcut} * whose ID matches: the entry is folded into that conversation, so it applies to the shortcut's message and to its * later messages as well. A conversation not started by a matching shortcut receives the entry only when the value * is `true`. */ chat?: boolean | RegExp; /** * Whether the entry is attached to AI Quick Action requests. Provide a `RegExp` to attach it only to actions * whose ID, or the ID of their group, matches. */ quickActions?: boolean | RegExp; /** * Whether the entry is attached to AI Review requests. Provide a `RegExp` to attach it only to review commands * whose ID matches. */ review?: boolean | RegExp; /** * Whether the entry is attached to AI Translate requests. Provide a `RegExp` to attach it only to translations * whose target language ID matches. */ translate?: boolean | RegExp; } /** * A single entry of the {@link module:ai/aiconfig~AIConfig#defaultContext global default context}. * * It is a {@link module:ai/aicore/model/aicontextref~AIContextRef context reference} optionally narrowed down to * specific features via `features`. When `features` is omitted, the entry is attached to **every** AI feature. */ export type AIDefaultContextEntry = AIContextRef & { /** * The features the entry is attached to. When omitted, the entry is attached to every AI feature. */ features?: AIDefaultContextFeatures; }; /** * The shape accepted by {@link module:ai/aiconfig~AIConfig#defaultContext}. * * A list of {@link module:ai/aicore/model/aidefaultcontext~AIDefaultContextEntry context references} attached * automatically to AI feature invocations triggered through the editor UI. Each entry can target all features or a * subset of them. The headless gateway APIs are config-independent and do not apply it. */ export type AIDefaultContext = Array;