@ckeditor/ckeditor5-ai
Version:
AI features for CKEditor 5.
311 lines (310 loc) • 9.96 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
*/
/**
* @module ai/aichat/aichatui
*/
import { type Context, type Editor, ContextPlugin } from 'ckeditor5/src/core.js';
import { AITabs } from '../aitabs/aitabs.js';
import { type AIAddContextOptionsState, type AIContextProvider, type AIContextResource, type AIContextResourceState } from './model/aichatcontext.js';
import { type AIContextItem } from '../aicore/model/aicontext.js';
import { type Document } from '../aicore/utils/htmlparser.js';
import { type AICapabilitiesConfig } from '../aicore/model/aicapabilities.js';
import { type AIReplySource, type AIReply, type AIReplyChangeGroupState } from '../aicore/model/aireply.js';
import { type AISuggestionContentPartDefinition } from '../aicore/utils/getsuggestionpartsfromreply.js';
import { type AIChatConversationInitializedEvent } from './model/aichatconversation.js';
import { type AIChatModel } from './model/aichatmodels.js';
import { type AIChatInteraction } from './model/aichatinteraction.js';
import { type AIContentRenderingStrategy } from '../aicore/ui/suggestioncontainer/aisuggestioncontentpartview.js';
import '../../theme/aichat/aichat.css';
export declare class AIChatUI extends ContextPlugin {
/**
* @inheritDoc
*/
static get requires(): readonly [typeof AITabs];
/**
* @inheritDoc
*/
static get pluginName(): "AIChatUI";
/**
* @inheritDoc
*/
static get isOfficialPlugin(): true;
/**
* @inheritDoc
*/
static get isPremiumPlugin(): true;
/**
* The busy state of the UI.
*
* It is set to `true` when there are AI response being streamed or rendered.
*
* @observable
*/
isBusy: boolean;
/**
* Indicates if the active model is available.
*
* @observable
*/
isModelAvailable: boolean;
/**
* @inheritDoc
*/
constructor(context: Context | Editor);
destroy(): void;
/**
* Creates a new conversation by greeting the user.
*/
createConversation(data: AIChatConversationInitializedEvent['args'][0]): void;
/**
* Adds a generic message to the chat feed.
*/
addFeedItemStaticMessage({ id, staticMessage }: {
id: string;
staticMessage?: string;
}): void;
/**
* Adds a user message to the chat feed.
*/
addFeedItemUserMessage(interaction: AIChatInteraction): void;
/**
* Adds an error message to the chat feed.
*/
addFeedItemError({ errorMessage, id }: {
errorMessage: string;
id: string;
}): void;
/**
* Adds an AI reply to the chat feed.
*/
addFeedItemAIReply(reply: AIReply): Promise<void>;
/**
* Adds an AI suggestion reply to the chat feed.
*/
addFeedItemAISuggestion(reply: AIReply): Promise<void>;
/**
* Adds an interaction header to the chat feed.
*/
addFeedInteractionHeader(interaction: AIChatInteraction, capabilities: AICapabilitiesConfig): void;
/**
* Updates the visibility of the interaction header in the chat feed.
*/
updateFeedInteractionHeader(options: {
isVisible: boolean;
id: string;
}): void;
/**
* Updates the content of an AI reply in the chat feed.
*/
updateFeedItemAIReplyContent(options: {
id: string;
parsedContent: Document;
renderingStrategy?: AIContentRenderingStrategy;
isDone?: boolean;
}): Promise<void>;
updateFeedItemAIReplySources(id: string, sources: Array<AIReplySource>): void;
/**
* Updates the content of an AI suggestion reply in the chat feed.
*/
updateFeedItemAIReplySuggestionContent(options: {
id: string;
parts: Array<AISuggestionContentPartDefinition>;
renderingStrategy?: AIContentRenderingStrategy;
isDone?: boolean;
}): Promise<void>;
updateFeedItemAIReplySuggestionPartState(options: {
id: string;
index: number;
state: AIReplyChangeGroupState;
}): void;
/**
* Removes an interaction from the chat feed. Interaction is a user message + one or more AI replies.
*/
removeFeedInteraction(interactionId: string): void;
/**
* Starts a new interaction processing in the UI and marks the UI as busy.
*/
startInteraction(): void;
/**
* Handles the user stopping the interaction. It terminates all scheduled UI update promises and unlocks the UI
* immediately.
*/
stopInteraction(interaction: AIChatInteraction): void;
/**
* Handles the interaction finishing due to lack of data to process (or an error). Waits for all pending UI
* updates to finish, then unlocks the UI.
*/
finishInteraction(): Promise<void>;
/**
* Adds an item chip to the current context list.
*/
addContextItem(contextItem: AIContextItem, isLoading: boolean): void;
/**
* Removes an item from the context as chip.
*/
removeContextItem(id: string): void;
/**
* Sets the loading state of an item chip in the current context list.
*/
setContextItemLoading(uiId: string, isLoading: boolean): void;
/**
* Sets the upload in progress state.
*/
setIsUploadInProgress(isUploadInProgress: boolean): void;
/**
* Sets the conversation context chips.
*/
setConversationContext(contextItems: Array<AIContextItem>): void;
/**
* Removes all chips from the current context list.
*/
clearPendingContextUI(): void;
/**
* Clears all chips from the conversation context list.
*/
clearConversationContextUI(): void;
/**
* Updates the state of a specific resource in the balloon views.
*/
updateResourceState(sourceId: string, resourceId: string, isInContext: boolean): void;
/**
* Resets the message input in the controls view.
*/
resetMessageInput(): void;
/**
* Sets the add context options in the UI.
*/
setAddContextOptions(options: AIAddContextOptionsState): void;
/**
* Updates the capabilities of the AI chat in the UI.
*/
updateCapabilities(capabilities: AICapabilitiesConfig): void;
/**
* Updates selected AI model in the controls view.
*/
setSelectedModel(model: AIChatModel, isDisabled?: boolean): void;
/**
* Sets the rendering strategy for the feed items. Streaming is default and uses HTMLStreamer to stream the content.
*
* Static works out for messages that must appear instantly.
*/
setFeedItemRenderingStrategy(strategy: 'streaming' | 'static'): void;
/**
* Toggles the loading skeleton in the chat feed.
*/
toggleLoadingSkeleton(isLoading: boolean): void;
/**
* Resets the conversation title to the default value.
*/
resetConversationTitle(): void;
/**
* Sets the title for the conversation.
*
* @param title The new title of the conversation.
* @param shouldAnimate Whether the title change should be animated. Defaults to `false`.
*/
setConversationTitle(title: string, shouldAnimate?: boolean): void;
/**
* Sets the loading message of the chat feed based on the passed model capabilities. If `null` is passed,
* the loading message is cleared.
*/
setLoadingMessage(capabilities: AICapabilitiesConfig | null): void;
setIsMaximized(isMaximized: boolean): void;
/**
* Populates a source resource balloon with loaded resources.
*/
populateSourceResourceBalloon(sourceId: string, source: AIContextProvider, resources: Array<AIContextResourceState>, uid: string): void;
/**
* Closes the source resource balloon and cleans up its state.
*/
closeSourceResourceBalloon(sourceId: string): void;
focusPromptInput(): void;
scrollFeedToSuggestion(replyId: string, partIndex: number): void;
startAutoScroll(): void;
disableControls(): void;
enableControls(): void;
}
/**
* An event fired when the user starts a new conversation.
*/
export type AIChatUIStartConversationEvent = {
name: 'startConversation';
args: [];
};
/**
* An event fired when the user sends a message to the AI.
*/
export type AIChatUISendUserMessageEvent = {
name: 'sendUserMessage';
args: [
string
];
};
/**
* An event fired when the user wants to abort the current interaction with the AI.
*/
export type AIChatUIAbortPromptStreamEvent = {
name: 'abortPromptStream';
args: [];
};
/**
* An event fired when the user wants to add a document to the context.
*/
export type AIChatUIAddDocumentToContextEvent = {
name: 'addDocumentToContext';
args: [];
};
/**
* An event fired when the user wants to add a file to the context.
*/
export type AIChatUIAddFileToContextEvent = {
name: 'addFileToContext';
args: [
Array<File>
];
};
/**
* An event fired when the user wants to add a URL to the context.
*/
export type AIChatUIAddUrlToContextEvent = {
name: 'addUrlToContext';
args: [
string
];
};
/**
* An event fired when the user wants to add a resource to the context.
*/
export type AIChatUIAddResourceToContextEvent = {
name: 'addResourceToContext';
args: [
{
source: AIContextProvider;
resource: AIContextResource;
}
];
};
/**
* An event fired when the user wants to remove a context item.
*/
export type AIChatUIRemoveContextItemEvent = {
name: 'removeContextItem';
args: [
string
];
};
/**
* An event fired when the user wants to load resources from a source provider.
*/
export type AIChatUILoadSourceResourcesEvent = {
name: 'loadSourceResources';
args: [
{
sourceId: string;
query: string;
uid: string;
}
];
};