@ckeditor/ckeditor5-ai
Version:
AI features for CKEditor 5.
136 lines (135 loc) • 4.92 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/aichat/ui/aichatfeedview
*/
import { type Locale } from '@ckeditor/ckeditor5-utils';
import { View, type ViewCollection, type BodyCollection } from '@ckeditor/ckeditor5-ui';
import { type AIChatFeedItemView } from './feed/aichatfeeditemview.js';
import { type AIContentRenderingStrategy } from '../../aicore/ui/suggestioncontainer/aisuggestionstreamablecontentview.js';
import { type Document } from '../../aicore/utils/htmlparser.js';
import { AIChatFeedSuggestionItemView } from './feed/aichatfeedsuggestionitemview.js';
import { AIChatFeedReplyItemView } from './feed/aichatfeedreplyitemview.js';
import { AIChatFeedUserMessageItemView } from './feed/aichatfeedusermessageitem.js';
import { AIChatFeedErrorItemView } from './feed/aichatfeederroritemview.js';
import { AIChatFeedInteractionHeaderView } from './feed/aichatfeedinteractionheaderview.js';
import { type AISuggestionContentPartDefinition } from '../../aicore/utils/getsuggestionpartsfromreply.js';
import { AIChatFeedCustomElementView } from './feed/aichatfeedcustomelementview.js';
import { type AIReplyChangeGroupState } from '../../aicore/model/aireply.js';
import { type AISource } from '../../aicore/aiconnector.js';
import '../../../theme/aichat/aichatfeed.css';
/**
* A view that displays the chat feed with various items.
*/
export declare class AIChatFeedView extends View {
/**
* A collection of feed items.
*/
readonly children: ViewCollection<AIChatFeedItemView>;
/**
* The loading message displayed when the feed is processing a response.
*
* When set, it gets displayed together with a loader spinner.
*
* @observable
*/
loadingMessage: string;
/**
* @observable
*/
isTrackChangesOn: boolean;
/**
* @inheritDoc
*/
constructor(locale: Locale, bodyCollection: BodyCollection);
render(): void;
destroy(): void;
/**
* Removes all items from the feed.
*/
clear(): void;
/**
* Adds a new item to the feed.
*/
addItem<T extends keyof ChatFeedAddItemTypesInstances>(itemType: T, options: ChatFeedAddItemTypesInstances[T]['options']): ChatFeedAddItemTypesInstances[T];
/**
* Updates the content of an item in the feed.
*
* **Note**: The content is updated (streamed) asynchronously.
*/
updateReplyItem({ id, parsedContent, renderingStrategy, abortSignal }: {
id: string;
parsedContent: Document;
renderingStrategy: AIContentRenderingStrategy;
abortSignal: AbortSignal;
}): Promise<void>;
updateWebSources(id: string, sources: Array<AISource>): Promise<void>;
updateSuggestionItem({ id, parts, abortSignal, skipLoadingEffects }: {
id: string;
parts: Array<AISuggestionContentPartDefinition>;
abortSignal: AbortSignal;
skipLoadingEffects?: boolean;
}): Promise<void>;
updateSuggestionPartState({ id, index, state }: {
id: string;
index: number;
state: AIReplyChangeGroupState;
}): void;
/**
* Sets the part active or not (active parts are those currently previewed in a dialog by the user).
*/
setSuggestionPartActive({ id, index, isActive }: {
id: string;
index: number;
isActive: boolean;
}): void;
/**
* Marks an item as done.
*
* **Note**: Marking the item as done cleans up the streaming animations.
*/
markItemAsDone(id: string): void;
/**
* Returns all item ids.
*/
getItemIds(): Array<string>;
/**
* Removes an item from the feed.
*/
removeItem(id: string): void;
/**
* Checks if an item exists in the feed.
*/
hasItem(id: string): boolean;
scrollToSuggestion(replyId: string, partIndex: number): void;
/**
* Sets the loading message of the chat feed.
*/
setLoadingMessage(message: string): void;
/**
* Toggles the loading skeleton in the feed.
*/
toggleLoadingSkeleton(isLoading: boolean): void;
/**
* Starts the auto-scrolling of the feed.
*
* @param options.smooth When `false`, the scroll jumps instantly instead of animating. Defaults to `true`.
*/
startAutoScroll(options?: {
smooth?: boolean;
}): void;
/**
* Stops the auto-scrolling of the feed.
*/
stopAutoScroll(): void;
}
export interface ChatFeedAddItemTypesInstances {
'interaction-header': AIChatFeedInteractionHeaderView;
'ai-reply': AIChatFeedReplyItemView;
'ai-suggestion-reply': AIChatFeedSuggestionItemView;
'user-message': AIChatFeedUserMessageItemView;
'error-message': AIChatFeedErrorItemView;
'custom-element': AIChatFeedCustomElementView;
}