@ckeditor/ckeditor5-ai
Version:
AI features for CKEditor 5.
187 lines (186 loc) • 5.81 kB
TypeScript
/**
* @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
*/
import { Element, Document } from '../utils/htmlparser.js';
import { type Editor } from 'ckeditor5/src/core.js';
import { type AISuggestionContentPartDefinition } from '../utils/getsuggestionpartsfromreply.js';
/**
* The reply types that are provided by the AI endpoint.
*/
export declare const AI_REPLY_TYPES: readonly ["modification-delta", "text-delta", "web-search", "reasoning"];
/**
* The reply types that are intentionally ignored.
*/
export declare const AI_REPLY_TYPES_IGNORED: readonly ["conversation-title"];
/**
* The type of the reply that is responsible for the conversation title.
*/
export declare const AI_REPLY_TITLE_TYPE = "conversation-title";
/**
* The type of the reply. It can be one of the following:
*
* * `modification-delta`: A content change suggestion made by the AI endpoint.
* * `text-delta`: A generic text response.
* * `source`: A source used by web search reply.
*/
export type AIReplyType = (typeof AI_REPLY_TYPES)[number];
declare const AIReply_base: {
new (): import("ckeditor5/src/utils.js").Observable;
prototype: import("ckeditor5/src/utils.js").Observable;
};
/**
* Represents a single reply from the AI endpoint.
*
* A reply's {@link #content} can be updated using the {@link #appendContent} method.
*/
export declare class AIReply extends /* #__PURE__ */ AIReply_base {
/**
* The ID of the reply.
*/
readonly id: string;
/**
* The ID of the interaction that the reply belongs to.
*/
readonly interactionId: string;
/**
* The type of the reply.
*/
readonly type: AIReplyType;
/**
* The content of the reply as received from AI endpoint.
*/
content: string;
/**
* The sources of the reply. Used for web search reply.
*/
sources: Array<AIReplySource>;
/**
* The parsed content of the reply.
*/
parsedContent: Document;
/**
* The parsed content of the reply after merging with the current document context.
*/
parsedMergedContent: Document;
/**
* TODO
*/
changeGroups: Array<AIReplyChangeGroup>;
/**
* Whether the reply is done. The reply is done once the AI endpoint emitted the last chunk of the content
* that matches the reply's type.
*/
isDone: boolean;
/**
* The document context of the reply.
*/
documentContextContent: Document;
/**
* @inheritDoc
*/
constructor({ type, content, isDone, interactionId, areActionsDisabled, documentContextContent, editor, id }: {
type: AIReplyType;
interactionId: string;
areActionsDisabled?: boolean;
content?: string;
isDone?: boolean;
documentContextContent?: string;
editor?: Editor;
id?: string;
});
/**
* Appends new content to the reply.
*
* See {@link #content} for more information.
*/
appendContent(content: string): void;
/**
* Marks the reply as done.
*
* See {@link #isDone} for more information.
*/
done(): void;
/**
* Destroys the reply.
*/
destroy(): void;
/**
* Changes the state of change group at `index` to `state`.
*
* Fires event.
*/
setChangeGroupState(index: number, state: AIReplyChangeGroupState): void;
/**
* Returns the content parts of the reply that correspond to {@link #changeGroups}.
*/
getContentParts({ showDiff, groupIndex }: {
showDiff: boolean;
groupIndex?: number;
}): Array<AISuggestionContentPartDefinition>;
}
/**
* Validates if the given reply type (SSE type) is a valid reply type.
*/
export declare function isValidReplyType(type: string | undefined): type is AIReplyType;
/**
* Checks whether the given reply type is ignored.
*/
export declare function isIgnoredReplyType(type: string | undefined): type is AIReplyType;
/**
* Checks whether the given reply type is a title reply.
*
* @param type The reply type to check.
* @returns True when the reply type is a title reply, otherwise false.
*/
export declare function isReplyTitleType(type: string | undefined): boolean;
export declare function isSourceType(type: string | undefined): boolean;
/**
* An event emitted by an {@link module:ai/aicore/model/aireply~AIReply} when it's
* {@link module:ai/aicore/model/aireply~AIReply#content} gets updated or the reply is marked as done.
*
* @eventName ~AIReply#replyContentUpdated
*/
export type AIReplyContentUpdatedEvent = {
name: 'replyContentUpdated';
args: [
reply: AIReply,
updatedChangeGroups?: Array<AIReplyChangeGroup>
];
};
/**
* An event emitted by an {@link module:ai/aicore/model/aireply~AIReply} when it's
* {@link module:ai/aicore/model/aireply~AIReply#content} gets updated or the reply is marked as done.
*
* @eventName ~AIReply#replyContentUpdated
*/
export type AIReplyChangeGroupStateUpdated = {
name: 'replyChangeGroupStateUpdated';
args: [
{
reply: AIReply;
index: number;
state: AIReplyChangeGroupState;
}
];
};
export type AIReplyHotNode = {
node: Element;
id: string;
type: AISuggestionContentPartDefinition['type'];
anchorId?: string | null;
};
export type AIReplyChangeGroup = {
readonly changes: Array<AIReplyHotNode>;
readonly index: number;
state: AIReplyChangeGroupState;
};
export type AIReplyChangeGroupState = 'pending' | 'accepted' | 'rejected' | 'outdated';
export type AIReplySource = {
type: string;
id: string;
url: string;
title: string;
favicon: string;
};
export {};