@ckeditor/ckeditor5-ai
Version:
AI features for CKEditor 5.
135 lines (134 loc) • 4.43 kB
TypeScript
/**
* @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/aireply
* @publicApi
*/
import { type Locale } from '@ckeditor/ckeditor5-utils';
import { Element, Document } from '../utils/htmlparser.js';
import { type AISuggestionContentPartDefinition } from '../utils/getsuggestionpartsfromreply.js';
import type { AISource } from '../aiconnector.js';
import type { AIDataIdDocumentSource } from './aicontext.js';
/**
* The type of the reply. It can be one of the following:
*
* * `modification`: A content change suggestion made by the AI endpoint.
* * `text`: A generic text response.
*/
export type AIReplyType = 'modification' | 'text';
declare const AIReply_base: {
new (): import("@ckeditor/ckeditor5-utils").Observable;
prototype: import("@ckeditor/ckeditor5-utils").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.
*
* @observable
*/
content: string;
/**
* The sources of the reply. Used for web search reply.
*/
sources: Array<AISource>;
/**
* The parsed content of the reply.
*
* This property is automatically updated after reply {@link #content} changes. You can add a listener to `replyContentUpdated` event
* in order to react to these changes.
*
* Note, that this property type is not DOM Document, but a simplified version provided by `domhandler` library.
*/
parsedContent: Document;
/**
* 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 or the reply was interrupted (user stop, error, connection drop).
*
* See {@link #isComplete} for more information about the reply's completion state.
*
* @observable
*/
isDone: boolean;
/**
* Whether the reply finished organically, i.e. the stream ran out of chunks naturally.
*
* This is `false` while streaming, and also `false` if the reply was stopped or errored before the stream ended.
*
* See {@link #isDone} for more information.
*
* @observable
*/
isComplete: boolean;
/**
* @inheritDoc
*/
constructor({ type, content, isDone, isComplete, interactionId, areActionsDisabled, isFromHistory, documentContextContent, dataIdDocumentSources, documentId, locale, id }: {
type: AIReplyType;
interactionId: string;
areActionsDisabled?: boolean;
isFromHistory?: boolean;
content?: string;
isDone?: boolean;
isComplete?: boolean;
documentContextContent?: string;
dataIdDocumentSources?: ReadonlyMap<string, AIDataIdDocumentSource>;
documentId?: string;
locale?: Locale;
id?: string;
});
/**
* Appends new content to the reply.
*
* See {@link #content} for more information.
*/
appendContent(content: string): void;
/**
* Destroys the reply.
*/
destroy(): void;
}
/**
* 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>
];
};
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 {};