/** * @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/aicontext * @publicApi */ import { type ObservableMixinConstructor } from "@ckeditor/ckeditor5-utils"; import { type AIEditorConfig } from "../utils/geteditorconfig.js"; import { type AIContextRef, type AIContextRefRequestData } from "./aicontextref.js"; /** * The type of context item. * * Available types: * * `'mcp-tool-context'`: a tool-related context item, * * `'file'`: a file (PDF, Word document, etc.), * * `'document'`: all current editors documents (one per each root in each editor), * * `'image'`: an image file — internal sub-type of file, derived from the file's MIME type * so the chip renders a distinct icon. Serialized to the backend as `'file'`. * (used by {@link module:ai/aichat/model/aichatcontext~AIChatContextConfig#document `config.ai.chat.context.document` option}), * * `'web-resource'`: a URL (web page, blog post, etc.), * * `'text'`: a text (plain text, Markdown, HTML, etc.), * * `'selection'`: a selection of text in the editor * (used by {@link module:ai/aiquickactions/aiquickactions~AIQuickActions AI Quick Actions} that pass the user selection * to the {@link module:ai/aichat/aichat~AIChat AI Chat}), * * `'context'`: a reference to an admin-managed context. */ export type AIContextItemType = "mcp-tool-context" | "file" | "image" | "document" | "web-resource" | "text" | "selection" | "context"; /** * The type of text resource. */ export type AIContextTextResourceType = "text" | "markdown" | "html"; /** * A context item. */ export type AIContextItem = AIContextItemRequestData & { label: string; uiId: string; resourceId?: string; isReadOnly?: boolean; version?: number; hidden?: boolean; sessionId?: string | null; selection?: Array<{ start: number; end: number; }>; }; /** * A tool-related context item. */ export type AIToolContextItem = AIContextItem & { type: "mcp-tool-context"; mcpServerName: string; toolName?: string; data: Record; /** * ID length can be between 1 and 21 characters. If not provided, it will be randomly generated 21 characters long string. */ id?: string; }; /** * A context item request data for using in the `AIConnector`. */ export type AIContextItemRequestData = { type: AIContextItemType; content?: string; id?: string; selection?: Array<{ start: number; end: number; }>; editorConfig?: AIEditorConfig; }; /** * A single entry in a request `content`/`parts` array: either a resolved context item or a * {@link module:ai/aicore/model/aicontextref~AIContextRefRequestData tagged reference} to an admin-managed context. */ export type AIContextRequestPart = AIContextItemRequestData | AIContextRefRequestData; export type AIToolRequestData = { type: "mcp-tool-context"; mcpServerName: string; toolName?: string; data: Record; }; declare const AIContextBase: ObservableMixinConstructor; /** * A set of context references attached to an AI request. * * It is the base context model shared by all AI features: features that do not manage interactive context * (Review, Translate, Quick Actions) use it directly, as the result of * {@link module:ai/aicore/model/aicontextlibrary~AIContextLibrary#resolveContext}, while * {@link module:ai/aichat/model/aichatcontext~AIChatContext} extends it with the chat-specific context state. */ export declare class AIContext extends AIContextBase { /** * @param refs The context references to hold. */ constructor(refs?: Array); /** * The context references, in resolution order. Returns a copy - mutating it does not affect the context. */ get refs(): Array; /** * Whether the context holds no references. */ get isEmpty(): boolean; /** * Returns a new context with the given references appended. The original context is left unchanged. Used to fold in * a feature's own reference (for example a review check's `context`). */ cloneWith(...refs: Array): AIContext; /** * Returns the request parts to send: the context's references followed by the given message parts. This is where the * leading references applied to every message are merged with a message's own context items. */ toRequestParts(parts?: Array): Array; /** * Merges the identifiers of this context's references into the given `message.attributes`, so they can be read * back from history to keep the references' pills hidden. Returns the given attributes unchanged when the context * holds no references. */ toMessageAttributes(attributes?: Record): Record | undefined; /** * Reads back the default context reference identifiers stored by {@link #toMessageAttributes} from a historical * message's `attributes`. */ static getDefaultContextIds(attributes?: Record): Set; } export {};